6

Is there a way to run one of the new (in macOS 12) Shortcut tasks on a schedule? It seems you can do it manually in a few different ways, but I'm not seeing a way to automate it.

It doesn't seem to hook up to the old Automator app, which I believe is probably going to go away at some point anyway. It doesn't seem to be available as an alert action in the calendar.

Specifically I'm looking at the shortcut to send a daily agenda email - this is pretty much a perfect case for scheduling something, since iCloud Calendar doesn't have it as an option - but it's pretty useless if I have to remember to click a button every morning.

user3439894
  • 55,813
  • 9
  • 101
  • 125
Joe Enos
  • 346
  • 2
  • 6
  • 17

4 Answers4

6

Based on @Gintaras's answer, since you can run a shortcut from a shell script, I was able to get it done - but not with launchd.

Instead, I created a new application in the Automator app, to run a shell script, with the contents:

#!/bin/sh

cd /Users/MY_USER_NAME
shortcuts run "Email Schedule to Yourself"

Then I added a recurring calendar entry at 6am, with a custom alert to open a file, and selected this app. When the time hit, the email was sent successfully.

I've read rumors that Automator is on the way out someday, so this may not be a permanent solution, but I'm sure it'll get us through the next several years.

And FYI: I tried skipping the Automator step and running that script directly from Calendar, but apparently Calendar doesn't like running shell scripts.

Joe Enos
  • 346
  • 2
  • 6
  • 17
5

Related question on Stack Overflow:

Scheduling a terminal command or script file to run daily at a specific time Mac OS X

People are using launchd to achieve this. Personally, i use mysql server events with lib_mysqludf_sys-master and dedicated table replicating events. Hard to setup everything, but it's very convenient to add/edit/remove jobs by simply editing mysql table's rows.

To run a shortcut from terminal:

shortcuts run "YOUR SHORTCUT NAME"

To run with launchd your plist file should look something like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>com.example.volume</string>
        <key>ProgramArguments</key>
        <array>
                <string>sh</string>
                <string>-c</string>
                <string>shortcuts run "YOUR SHORTCUT NAME"</string>
        </array>
        <key>StartCalendarInterval</key>
        <dict>
                <key>Hour</key>
                <integer>23</integer>
                <key>Minute</key>
                <integer>45</integer>
        </dict>
</dict>
</plist>
pkamb
  • 7,183
  • 9
  • 60
  • 99
Gintaras
  • 469
  • 2
  • 5
  • 4
    Seems a bit ridiculous to take a graphical programming interface like Shortcuts and have to use an incredibly user-unfriendly process like launchd to schedule it. Hoping there's a better way. – Joe Enos Oct 28 '21 at 12:37
  • 2
    You're right, there should be an App for that. Is there any app? I can't find anything similar on the Mac App Store. I might make one and put it on Mac App Store. – Gintaras Oct 28 '21 at 14:01
  • See my edit - not a fantastic solution, but it's not bad, and avoids stuff like cron or launchd. – Joe Enos Oct 28 '21 at 18:24
0

Another possible solution that still uses launchd but is configured through a GUI is using something like LaunchControl (https://soma-zone.com/LaunchControl/ , paid app). Again this is the same as @Gintaras 's answer but using a GUI instead of writing XML.

Edit: Another alternative is Lingon, a similar app that acts as a GUI to launchd (https://www.peterborgapps.com/lingon/ ) it's also a paid app...

Enrico
  • 192
  • 4
0

I was suffering the same trouble but found the easiest (and prob the official) way so far: use Shortcuts app on iOS instead of Mac!

On iOS ver, you can make personal automation to schedule shortcuts created on mac.

The only limitation is the whole task must be able to be completed on your phone but I actually found this is better for me cuz in this way you don't need to set up your mac to turn back from sleep.

  • Please note that the original question asked "in macOS 12" therefore using the Shortcuts in iOS isn't a solution Joe Enos is looking for. – agarza Sep 16 '22 at 16:44