Using Launch Agents to schedule automations on your Mac

Long time podcast listener, first time poster.

Over the years, I’ve learned just enough AppleScript and terminal commands to get my Mac to do what I want. But I always had a problem getting my Mac to do what I wanted when I wanted.

I used to use Automator to create calendar alarms, but they were temperamental and unreliable. I’m sure I injured a few scalp follicles due to pulling my hair in frustration.

I tried out the apps PowerManager and Keyboard Maestro. I was able to use them to create and schedule macros, and they certainly are wonderful apps. But then, I got caught—by the DIY bug! I decided to see if I could use the Mac’s built-in capabilities to achieve what I wanted. When I learned about Launch Agents, I felt like Hermione Granger discovering a powerful spell book.

Launch Agents often get mentioned in the context of looking for agents installed by third party, or even malicious, software, in order to remove them. However, they are simply a way that MacOS allows talking to launchd, the powerful daemon that starts the system at bootup and loads and runs services. I decided to create my own Launch Agents. It turned out to be very doable for a mere mortal. I now have written 10 launch agents to run various AppleScripts on my Mac at the times I find most useful. You can also schedule shell scripts or Automator workflows if those are your things.

Why bother? First, to go beyond the limits of the Mac GUI; second, for the fun of it! I have agents that:

  • sleep my Mac at different times on different days
  • orchestrate which AirPlay speakers should play what, when, and how loud
  • mount and run my Time Machine backup on my chosen schedule
  • export archives of my calendars and contacts weekly
  • randomize my screensaver daily

…and more. I finally feel like my powers of automation on the Mac have caught up to what I can do with Shortcuts on iOS. Now I feel like Hermione having just mastered the big spell book!

There are plenty of articles on the interwebs. I found these helpful:

1 Like

What is the benefit of this compared to a cron-job?

There’s a good overview of launchd vs cron here. Basically it is just more powerful/flexible.

It has also been Apple’s default option since 2011, so they effectively formally deprecated the use of cron on the Mac in favour of launchd about 10 years ago!

Great resources! I would add this one to the list:

2 Likes

Thanks, Tjluoma! LaunchControl looks like a great app for those wanting a bit of a guiding hand. I will happily pass it by, since I’ve had success with just using my usual text editor. :grinning:

I think it’s great that it’s possible to do this with a regular text editor. I’ve even created some of these plists programmatically. But I’m glad to have LaunchControl (or Lingon, another fine app) for those times when I want help.