While doing other stuff, I wrote this script to get a custom data string as an identifier.
Demo
-- y-yr m-mon d-day h-hr n-min s-sec
tell application id "DNtp"
set {a} to item 1 of {selection}
tell application "System Events"
set b to my getDateString(current date, "ymdhns", "-")
--returns. "2020-03-07-08-41-22"
set c to my getDateString(current date, "ymdh", ".")
--returns "2020.03.07.08"
end tell
set d to my getDateString(modification date of a, "ymdhn", "-")
--returns "2020-02-18-11-10"
set e to my getDateString(modification date of a, "dmy", "-")
--returns "18-02-2020"
end tell
The script needs to call three other handlers - I am used to calling my standard handlers to avoid re-writing the script each time. I am sure that it will be much easier to use shell script to do the same job. Perhaps somone will take the challenge…
The script (and the three handlers)
--ngan 2020.03.07
on getDateString(theDate, theFormat, theSeperator)
tell application id "DNtp"
local y, m, d, h, n, s, t
local lol, ds
set lol to {{"y", ""}, {"m", ""}, {"d", ""}, {"h", ""}, {"n", ""}, {"s", ""}}
set (lol's item 1)'s item 2 to get year of theDate
set (lol's item 2)'s item 2 to my PadNum((get month of theDate as integer) as string, 2)
set (lol's item 3)'s item 2 to my PadNum((get day of theDate) as string, 2)
set t to every word of (get time string of theDate)
set (lol's item 4)'s item 2 to T's item 1
set (lol's item 5)'s item 2 to T's item 2
set (lol's item 6)'s item 2 to T's item 3
end tell
set ds to {}
set theFormat to (every character of theFormat)
repeat with each in theFormat
set ds to ds & my lolLookup(each as string, 1, 2, lol)
end repeat
return my listToStr(ds, theSeperator)
end getDateString
on lolLookup(lookupVal, lookUpPos, getValPos, theList)
--only for lol with 2 items or more
local i, j, k
set j to lookUpPos
set k to getValPos
repeat with i from 1 to length of theList
if (item j of item i of theList) is equal to lookupVal then return {item k of item i of theList}
end repeat
return {}
end lolLookup
on PadNum(lngNum, lngDigits)
-- Credit houthakker
set strNum to lngNum as string
set lngGap to (lngDigits - (length of strNum))
repeat while lngGap > 0
set strNum to "0" & strNum
set lngGap to lngGap - 1
end repeat
strNum
end PadNum
on listToStr(theList, theDelimiter)
set {tid, text item delimiters} to {text item delimiters, theDelimiter}
set theStr to theList as text
set text item delimiters to tid
return theStr
end listToStr