13

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.

0

6 Answers 6

9

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>
4
  • 5
    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
    Commented Oct 28, 2021 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
    Commented Oct 28, 2021 at 14:01
  • See my edit - not a fantastic solution, but it's not bad, and avoids stuff like cron or launchd.
    – Joe Enos
    Commented Oct 28, 2021 at 18:24
  • I'm on macOS Sonoma 14.2. This solution works. I added logging as instructed by apple.stackexchange.com/a/435504/251842. For reason not really understood, Shortcuts must be run from a shell. Commented Dec 16, 2023 at 13:32
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.

Automator is needed since Calendar doesn't run this type of shell script that needs a graphical environment established directly.

2

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...

2
  • Why the downvotes?
    – Enrico
    Commented Dec 6, 2021 at 12:10
  • I so appreciate both Lingon and Launch Control and they are far more flexible than using Calendar and Automator (which is the best DIY - Apple tool only solution).
    – bmike
    Commented Nov 30, 2023 at 17:27
2

I found that @Gintaras's answer worked for me after a bit of troubleshooting. I kept encountering "Load failed: 5: Input/output error."

But once I unloaded and reloaded the .plist, it worked:

launchctl unload ~/Library/LaunchAgents/com.example.volume.plist
launchctl load ~/Library/LaunchAgents/com.example.volume.plist

ggruen's answer on this page was helpful

2

Since the answers posted here in 2021, Mac apps have come on the scene. All allow you to schedule shortcuts on macOS (and they have many more useful triggers). All are paid, but Trypa's free version (on dev's website) allows you one trigger.

I'm using the launchd method myself. Although easier to schedule via a calendar event, I don't like the clutter.

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.

1
  • 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
    Commented Sep 16, 2022 at 16:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .