Date Time Stamp Applescript formatting result is odd in Sonoma

I have programmed an AppleScript as a Service with the following code:


on run {input, parameters}


set thedate to (current date) as string


tell application "System Events"


keystroke thedate


end tell


end run


******

The result is Tuesday, January 30, 2024 at 5:39:56aPM.

I cannot figure out what the "a" before the "PM" means or how to remove it so that the end result is:

Tuesday, January 30, 2024 at 5:39:56 PM


Any help would be greatly appreciated!

MacBook Pro 16″, macOS 14.3

Posted on Jan 30, 2024 6:04 PM

Reply
2 replies

Jan 30, 2024 7:27 PM in response to Vetdocjim

The following seems a little more direct for showing the date:


display dialog (current date) as string



But you're probably trying to insert that date into some app?


If I run your code directly in Script Editor, I get error -1721, which means The wrong number of arguments was detected. Which undoubtedly means I'm not using the same app you're scripting.


on run {input, parameters}
    set thedate to (current date) as string
    tell application "System Events"
        keystroke thedate
    end tell
end run



I'd guess you're meeting something with the string or the encoding or the unspecified app.


Above tested on macOS 13.6.3.



This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Date Time Stamp Applescript formatting result is odd in Sonoma

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.