Timestamp

Good morning!

I used the instruction found on topic System-wide Insert Date & Time - Apple Community

to create a timestamp to use in mail, but I don't know how I can set the date format to be dd/mm/yyyy and the hours format to 24h even if my system preference are in 12h.

the script is this

on run {input, parameters} 

set thedate to (current date) as string 

tell application "System Events"

keystroke thedate 

	end tell

end run


can anyone help me?

MacBook Air (M1, 2020)

Posted on May 21, 2023 4:49 AM

Reply
Question marked as Top-ranking reply

Posted on May 21, 2023 5:50 AM

There is simpler date formatting available using the UNIX date command and supported strftime(3) symbology to arrive at your date format.


In the Automator Quick Action, set Workflow receives [ no input ] in [ any application ]. Also, select:


☑︎ Output replaces selected text


There won't be any selected text but if you want this action to return a date string into Mail (or anywhere else), you need this selected. The escaped (e.g. \") quotes are necessary in AppleScript.


Now the Quick Action workflow:


use scripting additions

on run {input, parameters}
	-- see https://pubs.opengroup.org/onlinepubs/007908799/xsh/strftime.html
	-- for UNIX date formatting codes
	set thedate to (do shell script "date -j +\"%d/%m/%Y %T\" ") as text
	return thedate
end run

And when you select Mail > Services menu (or unique keyboard shortcut) for this Quick Action, the following date string will be inserted:


21/05/2023 08:45:48


Tested: macOS 13.4

8 replies
Question marked as Top-ranking reply

May 21, 2023 5:50 AM in response to pierrelety

There is simpler date formatting available using the UNIX date command and supported strftime(3) symbology to arrive at your date format.


In the Automator Quick Action, set Workflow receives [ no input ] in [ any application ]. Also, select:


☑︎ Output replaces selected text


There won't be any selected text but if you want this action to return a date string into Mail (or anywhere else), you need this selected. The escaped (e.g. \") quotes are necessary in AppleScript.


Now the Quick Action workflow:


use scripting additions

on run {input, parameters}
	-- see https://pubs.opengroup.org/onlinepubs/007908799/xsh/strftime.html
	-- for UNIX date formatting codes
	set thedate to (do shell script "date -j +\"%d/%m/%Y %T\" ") as text
	return thedate
end run

And when you select Mail > Services menu (or unique keyboard shortcut) for this Quick Action, the following date string will be inserted:


21/05/2023 08:45:48


Tested: macOS 13.4

May 21, 2023 6:43 AM in response to pierrelety

Use the following to adjust the date 48 hours into the future:


date -j -v+48H +"%d/%m/%Y %T"


You can read more about the UNIX (as implemented on macOS) date command by entering this URI string in the Safari address field:


x-man-page://date


or from the command-line in the Terminal as:


man date



I chose the UNIX date command for your solution as although you could eventually manipulate AppleScript date/time data to arrive at the desired output, it would take considerable code and teeth gnashing to get it done.

May 21, 2023 6:50 AM in response to VikingOSX

use scripting additions

on run {input, parameters}

	set thedate to (do shell script "date -j -v+48H +"%d/%m/%Y %T\" ") as text

	return thedate

end run


You mean write the script like this?

it gives me syntax error

and shows this message on trying to run the command

The action “Run AppleScript” encountered an error: “The operation couldn’t be completed. (com.apple.Automator error -212.)”


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.

Timestamp

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