Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Automator - Date & Time script

I'm looking to create a date & time-stamp in Automator with a specific combination of a short date (MM/DD/YYYY) and timestamp (HH:MM:SS XM). I've looked around but have not found an answer to my specific question, closest script I've found is:


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


However this script generates the full date including the day of the full-length week and month:

Thursday, January 15, 2021 at 12:31:54 PM


I then tried changing it to:


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


But now it only shows the date and no time.


1/15/2021


How the heck to I combine the two to show both the current short date and a timestamp?

Posted on Jan 15, 2021 12:37 PM

Reply
Question marked as Best reply

Posted on Jan 15, 2021 1:34 PM

This is simpler:


use scripting additions

set iso8601fmt to (do shell script "date -j +\"%F %X\"") as text
tell application "System Events" to keystroke iso8601fmt


result: "2021-01-15 16:28:34"


You can see all of the percent formatting codes from the FreeBSD online man page for strftime.

Similar questions

1 reply

Automator - Date & Time script

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