Launchctl

Write a script to let the Mac run certain task at each login or at predefined time.

Steps:

1) Write a .plist file

e.g., local.save_timeclock.plist

<?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>local.save_timeclock</string> <key>Program</key> <string>/Users/henry/save_timeclock.sh</string> <key>StartCalendarInterval</key> <dict> <key>Hour</key> <integer>9</integer> <key>Minute</key> <integer>0</integer> </dict> </dict></plist>

2) Check the validity of the .plist file.

plutil ./local.save_timeclock.plist 

3) Load job

(Store the file at ~/Library/LaunchAgents/ first)

launchctl load ~/Library/LaunchAgents/local.save_timeclock.plist

4) Check whether the job is loaded

launchctl list | grep save*

5) Start running the job instantly

launchctl start local.save_timeclock.plist