r/applescript • u/bullsplaytonight • Jan 08 '24
Some time ago, my script to insert current date/time with a keystroke started inserting an extra "a" character and I can't figure out why.
When I do my keystroke (cmd, opt, crtl + D), the system spits out: Monday, January 8, 2024 at 10:49:15aAM
Can't figure out the "a" between 5 and AM. Started doing this a year ago, maybe, and am finally trying to investigate this morning.
on run {input, parameters}
set thedate to (current date) as string
tell application "System Events"
set the clipboard to thedate
tell application "System Events" to keystroke (the clipboard as text)
end tell
end run
4
Upvotes
2
u/estockly Jan 08 '24
The date conversion to string in appleScript uses your system setting for dates, which can be edited manually in the System Preferences app.
Look at:
System Preferences>Language & Regions>Advanced...>Times
Look in the "Medium" field and see if the extra character was added there.
1
u/estockly Jan 09 '24
I've asked around and haven't found a way to change that setting in Sonoma. If you find a way to change it via shell scripting or something else, please share.
1
u/KaiHawaiiZwei Jan 11 '24
i posted this a while ago, dunno if it helps.
set Now to current dateset Stamp to ((year of Now) - 2000) div 10 & ((year of Now) - 2000) mod 10 & "." & (month of Now) div 10 & (month of Now) mod 10 & "." & (day of Now) div 10 & (day of Now) mod 10 & " | " & (hours of Now) div 10 & (hours of Now) mod 10 & ":" & (minutes of Now) div 10 & (minutes of Now) mod 10 & ":" & (seconds of Now) div 10 & (seconds of Now) mod 10 as text