Created
May 15, 2015 22:26
-
-
Save 23maverick23/9e8757fa27e56c8422a3 to your computer and use it in GitHub Desktop.
Bash: Schedule jobs on Mac using launchd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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