The Mac runs on Unix, which makes it incredibly powerful. You might be running MAMP or a stand-alone version of Apache, and one of the things that you might want to run is cron, which is a scheduling tool. Instead of cron though, you could actually have your Mac just run a launch daemon.
Just go to terminal, and type:
cd /Library/LaunchDaemons/
Now type:
sudo vim yourfile.cron.plist
You’ll be asked for your administrator password, and after entering it, you’ll be brought to the vim screen. Press fn+i to go into insert mode. Now paste the following in:
<?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">
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key><false />
<key>Label</key><string>yourfile.cron</string>
<key>ProgramArguments</key>
<array>
<string>curl</string>
<string>-s</string>
<string>http://localhost:8080/cron.php</string>
</array>
<key>RunAtLoad</key>
<true />
<key>StartInterval</key><integer>1200</integer>
<key>StandardErrorPath</key><string>/dev/null</string>
<key>StandardOutPath</key><string>/dev/null</string>
</dict></plist>
Once done, press esc, and type :wq to save and quit.
This will actually create the property list file that will contain the information of the task that you want to run. Just paste in the following code, remembering to change “yourfile.cron” to your actual filename (notice this is the same as your filename, but without the .plist extension), and modifying the Program Arguments to fit your needs.
StartInterval is currently set at 1200, which is 20 minutes in seconds (20 minutes * 60 seconds). So if you want to, change this value too.
When you’re done editing, just hit esc, and type in :wq to write the file and quit. Now that the file is saved (you will probably need to enter your administrator password), just run the following commands to load the daemon:
sudo launchctl load /Library/LaunchDaemons/yourfile.cron.plist
Or unload the daemon:
sudo launchctl unload /Library/LaunchDaemons/yourfile.cron.plist
And there you have it – the way to run cron or cron-like jobs with your Mac!
Similar Posts:
- How To Reset The MySQL Root User Password and Privileges
- Common Useful UNIX Commands
- How To Mount An ISO File in Mac OS X
- How To Make and Run Batch Files In Terminal In Mac OSX
- How To Find Out What’s Locking Files or Folders in Mac


Leave a Reply