MacOS – change launchd program arguments based on calendar interval


I'm trying to run a script ( to automate snapshots, but one of the arguments needs to change based on which time entry triggers the script to start. With cron, I would just add a new line with the changed argument and set the time fields accordingly.

In reading the launchd and launchd.conf man pages, I'm not seeing any way to associate an argument with a specific StartCalendarInterval key entry. This seems like a significant limitation, so perhaps I'm missing something?

Is there a way change an argument based on the time the script is being run? Or, do I have to make a new plist for each of the situations I'm trying to satisfy?

Best Answer

The "standard" thing to do is make a new .plist for each different time/argument combo. This is essentially the equivalent of making multiple entries in the crontab, except that each "entry" is an entire file, not just a line.

There's a good example of this in macOS's launch daemon entries for the periodic maintenance program. /System/Library/LaunchDaemons/ runs /usr/libexec/periodic-wrapper with the argument "daily" and a 24-hour interval, ...periodic-weekly.plist runs it with the argument "weekly" and a 7-day interval, and ...periodic-monthly.plist runs it with the argument "monthly" and a 30.44-day interval.