How to use Launchd? [duplicate]
launchd
manages the daemon(s) that ultimately run your job (in your case an scpt). But in a setup similar to the "man behind the curtain" in The Wizard of Oz you don't talk directly to launchd
. Instead, you will prepare a .plist
(property list) file that will be parsed by launchctl
, and only then presented to launchd
for action.
I did this (manually created a .plist file) a while ago, and wrote up a brief "how-to" that you can find on this GitHub page. My experience was that writing an error-free .plist
file from scratch is arcane and error-prone, but I'm sure one gets better with practice!
Note that this example was done on Mojave - not on Catalina. And as with various other things, Apple has made access to launchd
(the man behind the curtain) more difficult in the name of security. In other words, the sample from my GitHub page runs successfully on Mojave, but it will not run on Catalina without hacking around Apple's more restrictive security measures.
Which brings me to the point of this: Instead of manually creating a .plist
file, you may wish to consider using a third-party tool called LaunchControl. For Catalina, 'LaunchControl' now includes a "helper tool" called fdautil
that simplifies cooperation with Apple's security mechanisms. I've used it successfully for two UserAgent jobs that run under launchd
on Catalina.