Mac uses launchctl to regularly run programs. in linux, crontab can be used to periodically execute tasks, in mac, launchctl can be used for scheduled task execution. In this example, we use launchctl to create a scheduled task execution script. The Script Name Is run123.sh, the script function is to create a file under the/Users/alecyan/Downloads/directory. The script should be changed to the executable permission chmod 777 run123.sh. The script code is as follows: java code cd/Users/alecyan/Downloads/touch abcabc123.txt and then enter ~ Create a plist file under/Library/LaunchAgents. This is the file name used by the worker system to execute the task. The file name is com. alecyan. testcron. plist. The content of the file is as follows: Java code <? Xml version = "1.0" encoding = "UTF-8"?> <! DOCTYPE plist PUBLIC "-// Apple // dtd plist 1.0 // EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version = "1.0"> <dict> <key> Label </key> <string> com. alecyan. testcron </string> <key> ProgramArguments </key> <array> <string>/Users/alecyan/Downloads/run123.sh </string> </array> <key> StartCalendarInterval </key> <dict> <key> Minute </key> <integer> 4 </integer> <key> Hour </key> <integer> 13 </integer> </ Dict> <key> StandardOutPath </key> <string>/Users/alecyan/Downloads/abc. log </string> <key> StandardErrorPath </key> <string>/Users/alecyan/Downloads/abcerror. log </string> </dict> </plist> briefly describes the content here. label indicates the name of the task. Here, the plist file name is generally used, this name cannot be the same as other plist names. Run123.sh is the script we want to execute, the parameter in StartCalendarInterval indicates that the script can be executed at every day, and then the following commands can be used to operate the task. The Java code launchctl load com is completed. alecyan. testcron. plist launchctl unload com. alecyan. testcron. plist launchctl start com. alecyan. testcron. plist launchctl stop com. alecyan. testcron. plist launchctl list to load the plist file we have prepared, it is to use the first command load ran, at this time, the compaction system will execute our script at every day. If you want to remove our scheduled task, you can run the unload command. If a task has been executed at today, then you changed it. com. alecyan. testcron. for example, if the time in plist is changed to, it must be unloaded and re-loaded. Otherwise, the start command will not be executed on the same day to test the task. This command is executed immediately, no matter when the time is reached, you can stop the task. OK. A simple scheduled task can be used. In fact, there are usually three directories such as/Library/LaunchAgents on mac, we are talking about the contents in the current user's directory, there are two other users in/Library/LaunchAgents and the other one in/System/Library/LaunchAgents/. If no user needs to execute them regularly, they should be placed under/Library/LaunchAgents.