Skip to content

Instantly share code, notes, and snippets.

@23maverick23
Created May 15, 2015 22:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 23maverick23/9e8757fa27e56c8422a3 to your computer and use it in GitHub Desktop.
Save 23maverick23/9e8757fa27e56c8422a3 to your computer and use it in GitHub Desktop.
Bash: Schedule jobs on Mac using launchd
# Activate rvm
$ rvm use default
# Install lunchy if not already installed
$ gem install lunchy
# Make a plist file
$ touch ~/Library/LaunchAgents/org.yourusername.email-mom.plist
# Open your plist file and copy the text from below
# Load and start your new agent
## With the built in `launchctl`
$ launchctl load ~/Library/org.yourusername.email-mom.plist
$ launchctl start org.yourusername.email-mom
## Or with Lunchy
## `restart` will unload your agent (if it's loaded), load it, then start the job
## Lunchy sees the argument as a pattern, so you don't have to specify the entire agent-name
$ lunchy restart email-mom
# Show loaded agents
$ launchctl list
# OR
$ lunchy list
# Stop an agent
$ launchctl org.yourusername.email-mom
# OR
$ lunchy stop email-mom
<?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>
<!-- The label should be the same as the filename without the extension -->
<string>org.yourusername.email-mom</string>
<!-- Specify how to run your program here -->
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/python</string>
<string>/Users/yourusername/bin/email.py</string>
<string>mom@home.com</string>
</array>
<!-- Run every hour -->
<key>StartInterval</key>
<integer>3600</integer><!-- seconds -->
<!-- StartCalendarInterval examples
<!-- Run every Sunday (weekday 0) at 15:30/3:30PM -->
<key>StartCalendarInterval</key>
<dict>
<key>Weekday</key>
<integer>0</integer>
<key>Hour</key>
<integer>15</integer>
<key>Minute</key>
<integer>30</integer>
</dict>
<!-- You can use an array of dicts to specify multiple intervals -->
<!-- Run at the beginning and middle of every hour, every day -->
<key>StartCalendarInterval</key>
<array>
<dict>
<key>Minute</key>
<integer>0</integer>
</dict>
<dict>
<key>Minute</key>
<integer>30</integer>
</dict>
</array>
-->
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment