There are two ways to schedule timed jobs on macOS: cron or launchd.
Which one is better?
(Darwin note: Although cron(8) and crontab(5) are officially supported under Darwin, their functionality has been absorbed into launchd(8), which provides a more flexible way of automatically executing commands. See launchd.plist(5) for more information.)
Although there is a note as above, cron and crontab are not to be replaced completely by launchd even on macOS as more difficult schedules can be realized by combining multiple cron expressions. There are some examples as below:
field
Ranges: 8-11 for an hours entry specifies execution at hours 8, 9, 10 and 11.
Lists: 1,2,5,9, 0-4,8-12
Step values: 0-23/2 can be used in the hours field to specify command execution every other hour.
The same usage is not working in plist file.
prefixed @AppleNotOnBattery
For example, the sixth field when using this option would appear something like @AppleNotOnBattery /usr/bin/touch /tmp/foo to tell cron not to run the command when functioning on battery power.
eight special strings
Instead of the first five fields, one of eight special strings may appear:
| string | meaning |
|---|---|
| @reboot | Run once, at startup. |
| @yearly | Run once a year, "0 0 1 1 _". |
| @annually | (same as @yearly) |
| @monthly | Run once a month, "0 0 1 _ _". |
| @weekly | Run once a week, "0 0 _ _ 0". |
| @daily | Run once a day, "0 0 _ * _". |
| @midnight | (same as @daily) |
| @hourly | Run once an hour, "0 _ * * *". |
Note: Don't use @reboot because there are too many issues.