Taking pity on you for that highly compressed but fast way of getting a time stamp, here’s a script that does what it does in a different (and much more obvious) way. The other is a clever way due originally to Nigel Garvey and contributed to by Kai, for getting two characters for each part by adding them to a large number after multiplying them by a constant that shifts them to the right decimal position.
makeTimeStamp((current date), ".")
-- aDelim should be one character of text
to makeTimeStamp(aDate, aDelim)
-- Get our pieces
tell aDate -- to avoid having to repeat "of aDate" in every line, replacing it with "its".
set yr to its year
set mo to its month as number
set dy to its day
set hr to its hours
set mn to its minutes
set sc to its seconds
end tell
-- Build our stamp
set TS to "" -- initialize our output string to an empty string
--return {yr, mo, dy, hr, mn, sc} -- uncomment to see the values of the parts
repeat with D in {yr, mo, dy, hr, mn, sc} -- adjust each of the parts to be two characters
if length of ((contents of D) as text) < 2 then set contents of D to "0" & D -- stick a "0" in front of single.
set TS to TS & D & aDelim -- add this piece to the rest (called concatination)
end repeat
return characters 3 thru -2 of TS as string -- skip the "20", and the final "aDelim character".
end makeTimeStamp
In slightly more compressed form:
makeTimeStamp((current date), ".")
-- aDelim should be one character of text
to makeTimeStamp(aDate, aDelim)
-- Get our pieces
tell aDate to set {yr, mo, dy, hr, mn, sc} to {its year, its month as number, its day, its hours, its minutes, its seconds} -- AppleScript understands assigning values to list items, and "telling" aDate enables us to use "its" in place of "of aDate" in every entry.
-- Build our stamp
set TS to "" -- initialize our output string to an empty string
--return {yr, mo, dy, hr, mn, sc} -- uncomment to see the values of the parts
repeat with D in {yr, mo, dy, hr, mn, sc} -- adjust each of the parts to be two characters
if length of ((contents of D) as text) < 2 then set contents of D to "0" & D -- stick a "0" in front of single.
set TS to TS & D & aDelim -- add this piece to the rest (called concatination)
end repeat
return characters 3 thru -2 of TS as string -- skip the "20", and the final "aDelim character".
end makeTimeStamp