Applescript – Automator – tomorrow keyboard shortcut

applescriptautomator

I've been able to successfully create a keyboard shortcut from a "quick action" in Automator based on running AppleScript (inserts current system date). However, I cannot get a similar script to work for inserting tomorrow's date (current date + 1 day) or the day after (current date + 2 days).

Here's what I have:

on run {input, parameters}

    set thedate to (current date) as string
    set myNewDate to thedate + (1 * days)
    tell application "System Events"
        keystroke myNewDate
    end tell
end run

It produces this Syntax Error:

Can’t make "Tuesday, March 5, 2019 at 10:13:55 AM" into type number.

Can someone help me identify my error and fix it? Apple support won't help with AppleScript-related issues for non-developers.

Any help is greatly appreciated by this novice coder.

Thank you to Allan, Ɱark Ƭ, Wowfunhappy and others for the quick help (not just a fix, but defining my syntax issue). I have a modification: how do I tell the string to leave off the time stamp at the end: "at 12:24:21 AM" ?

Best Answer

You are trying to add the day in the wrong spot. Try this:

set thedate to ((current date) + (days * 1)) as string
tell application "System Events"
    keystroke thedate
end tell

The "current date" returns the time in seconds, so you have to add one day worth of seconds (86,400 seconds in a day, but I'm sure you knew that) to get tomorrow. Change the multiplier to get more days in the future or past by using a negative value for the multiplier.

Note that not all days have 86400 seconds (DST change is +/- 3600, Leap seconds, etc…) so on some days it may be an hour off.