Automator AppleScript not working

I have the following AppleScript commands in an Automator workflow that I then saved as a Service:


tell application "System Events"
	set _Date to (current date)
	keystroke ¬
		(year of _Date as text) & "-" & ¬
		text -2 thru -1 of ("00" & ((month of _Date) as integer)) & "-" & ¬
		text -2 thru -1 of ("00" & ((day of _Date) as integer)) & " - "
end tell


In High Sierra this used to allow me to insert the current date in a standardized format anywhere in the OS, e.g. in notes, while editing a filename, etc. It no longer works in Mojave or later. Is there a change that needs to be made when invoking the System Events application?

MacBook Air 13″, macOS 10.14

Posted on Mar 17, 2021 5:10 PM

Reply

Similar questions

2 replies

Mar 18, 2021 2:46 AM in response to shaolin11

Apple really increased security with Mojave and later. Automator will not permit System Events keystrokes without some security help. In System Preferences > Security & Privacy > Privacy panel, do the following:


  • In Accessibility, add [+] Automator
  • In Full Disk Access, again, add [+] Automator


If you receive any dialog from Automator asking permissions to control anything, click OK, or suffer for clicking cancel.


Following the preceding bullet items, I would create a new Automator Quick Action (service) on Mojave and enter your posted code in the Run AppleScript action, and then save it. Use that Quick Action on Mojave.


Alternatively, you could use a Run Shell Script action with the following code:


date -j '+%F - '

which also produces "2021-03-18 - " .

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.

Automator AppleScript not working

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