MacOS Shortcut scheduling using launchctl

richard moult
3 min readJan 14, 2023

--

Let’s cover how to trigger Shortcuts apps at specific time, or on a specific day or month. Perhaps you want to run a shortcut each time you login into your machine. With the power of launchctl, you can automate this process.

Launchctl

launchctl is a command-line utility for managing and scheduling system-level tasks on macOS. One way to use launchctl to schedule a task is to create a property list (.plist) file with the desired launch conditions and use the launchctl load command to start the task and launchctl unload to stop the task.

Here’s a step-by-step guide on how to use launchctl and a plist file to schedule a task to run at a specific time of the day.

Step 1

Create a new <name>.plist file and specify the task you want to run. A .plist file is an XML file that contains keys and values that specify the task and any additional flags or parameters. The Program key specifies the path to the command or script to run, and the StartCalendarInterval key specifies the time and/or day to run the task. I’ll show examples of plist after the steps.

Step 2

Load the <name>.plist file and start the scheduled task by entering the following command in Terminal: launchctl load path/to/.plist. Replace ‘path/to/.plist’ with the actual file path to your plist file.

Step 3

To verify that the task has been scheduled, use the launchctl list command. This will show a list of all the tasks that have been scheduled with launchctl.

Step 4

To stop the scheduled task, use the unload command: launchctl unload path/to/.plist .

Schedule Time Example

I have an awesome Shortcut app called “Amazing” and I’d like to schedule that at 1:15pm every day.

Somewhere in your filing system, for this example let’s use the folder user/shortcuts, and create a new file called AmazingShortcut.plist with the following details

com.example.shortcut is a unique name, so for each plist you create use different text.

ProgramArgument is the command to call when the trigger fires, so if you have your own Shortcut called “Bob” simply switch shortcuts run "Bob" .

StartCalendarInterval is your time trigger as a 24hr clock. This example runs the command at 1:15pm. But there are more options that]n just the time of day, you can also set the weekday, day or month as well. See complete list below…

Minute <integer> The minute (0–59) on which this job will be run.

Hour <integer> The hour (0–23) on which this job will be run.

Day <integer> The day of the month (1–31) on which this job will be run.

Weekday <integer> The weekday on which this job will be run (0 and 7 are Sunday). If both Day and Weekday are specificed, then the job will be started if either one matches the current date.

Month <integer> The month (1–12) on which this job will be run.

Now we have our plist we can test it out. Open the Terminal app and enter the command

launchctl load user/shortcuts/AmazingShortcut.plist

If you now wait until 1:15pm that shortcut will now fire.

However once the tasks has fired you will need to call the same Terminal command each day. We can do better than that though, so let’s get that plist to automatically trigger for us each day.

To auto trigger the plist simply place the plist file into the folder Library/LaunchAgents , now each time you login into your machine the Shortcut will automatically fire each day at 1:15pm.

Launchctl comes with a lot more options, for more details, open the Terminal app and enter

man launchd.plist

If you need more complex date scheduling you can also use the Calendar, read more about that here.

If you found this blog post helpful, you’ll love the book packed with plenty of real-world examples and AI integration — dive deep into Shortcuts.

And for more shortcut ideas, tips and tricks, try this link out.

Happy scheduling 🥷.

--

--