Inserting Date & Time on Mac OS

After spending twenty minutes Googling and setting up a simple Mac OS service to insert the current date and time (formatted as 2018-09-03 16.36) I thought I'd document the steps quickly.

It's very simple to set up the service using Mac's Automator:


on run {input, parameters}
        set dateString to do shell script "date +'%Y-%m-%d %k.%M'"
        tell application "System Events"
                keystroke dateString
        end tell
        return input
end run


Some interesting sticky points:

AppleScript seems at one and the same time remarkably powerful and painful: I suspect the best way to use it is to use it carefully as a glue language, dropping out to an actual programming language (say Rust, or Python) for any actual computation.

view source