MacOS: Using Launchd

Launchd is the preferred way to run scripts on a schedule or timed basis on MacOS (like cron).
For this specific example, Ill be running a script every 60 seconds.

The launchd file should be located in the /Library/LaunchAgents directory within your home directory, for example:
/Users/L0r3/Library/LaunchAgents/com.L0r3.hueZoom
Once the launchd file is in place, it needs to be loaded:
$ launchtctl load /Users/L0r3/Library/LaunchAgents/com.im_L0r3.hueZoom.plist

List currently loaded launchd file:
$ launchtcl list

Unload launchd files like:
$ launchtctl unload /Users/L0r3/Library/LaunchAgents/com.im_L0r3.hueZoom.plist

The script that this example launchd file will run is located at: /Users/L0r3/scripts/hueZoom.sh
Launchd will run it every 60 seconds
Use code example below for your launchd file, adjusting the Label, ProgramArguments, StandardErrorPath, and StandardOutPath.

The Label is what it will be know as in launchd
The ProgramArguments is where the path to the script to run goes
The StartInterval is in seconds

The StandardErrorPath and StandardOutPath are log the log files

Launchd Code


0/5 : Not rated