125 lines
3.8 KiB
Markdown
125 lines
3.8 KiB
Markdown
<img src="https://cdn.rawgit.com/herrbischoff/awesome-osx-command-line/master/assets/logo.svg" width="600">
|
|
|
|
# LaunchAgents
|
|
|
|
> An assorted collection of useful LaunchAgent examples. Part of [Awesome OS X Command Line](https://github.com/herrbischoff/awesome-osx-command-line).
|
|
|
|
## Table of Contents
|
|
|
|
- [Basic Examples](#basic-examples)
|
|
- [Homebrew](#homebrew)
|
|
|
|
## Basic Examples
|
|
|
|
### Periodical Job Template
|
|
Run job every 5 minutes.
|
|
```xml
|
|
<?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.example.touchsomefile</string>
|
|
<key>ProgramArguments</key>
|
|
<array>
|
|
<string>touch</string>
|
|
<string>/tmp/helloworld</string>
|
|
</array>
|
|
<key>StartInterval</key>
|
|
<integer>300</integer>
|
|
</dict>
|
|
</plist>
|
|
```
|
|
|
|
### Periodical via Calendar Interval Job Template
|
|
```xml
|
|
<?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.example.touchsomefile</string>
|
|
<key>ProgramArguments</key>
|
|
<array>
|
|
<string>touch</string>
|
|
<string>/tmp/helloworld</string>
|
|
</array>
|
|
<key>StartCalendarInterval</key>
|
|
<dict>
|
|
<key>Minute</key>
|
|
<integer>45</integer>
|
|
<key>Hour</key>
|
|
<integer>13</integer>
|
|
<key>Day</key>
|
|
<integer>7</integer>
|
|
</dict>
|
|
</dict>
|
|
</plist>
|
|
```
|
|
|
|
### Monitoring Folder Job Template
|
|
```xml
|
|
<?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.example.watchhostconfig</string>
|
|
<key>ProgramArguments</key>
|
|
<array>
|
|
<string>syslog</string>
|
|
<string>-s</string>
|
|
<string>-l</string>
|
|
<string>notice</string>
|
|
<string>somebody touched /etc/hostconfig</string>
|
|
</array>
|
|
<key>WatchPaths</key>
|
|
<array>
|
|
<string>/etc/hostconfig</string>
|
|
</array>
|
|
</dict>
|
|
</plist>
|
|
```
|
|
|
|
|
|
## Homebrew
|
|
|
|
### Periodic Homebrew Update and Upgrade
|
|
To leverage the notification system, this agent requires [terminal-notifier](https://github.com/julienXX/terminal-notifier), which can be installed via `brew install terminal-notifier`.
|
|
```xml
|
|
<?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.example.homebrew-upgrade</string>
|
|
<key>ProcessType</key>
|
|
<string>Background</string>
|
|
<key>ProgramArguments</key>
|
|
<array>
|
|
<string>/bin/sh</string>
|
|
<string>-c</string>
|
|
<string>/usr/local/bin/brew update && /usr/local/bin/brew upgrade && /usr/local/bin/terminal-notifier -title 'Homebrew Upgrader' -message 'Homebrew upgraded!' -appIcon http://cdn.curvve.com/wp-content/uploads/2013/09/homebrew_osx_logo.png</string>
|
|
</array>
|
|
<key>RunAtLoad</key>
|
|
<true/>
|
|
<key>StandardErrorPath</key>
|
|
<string>/tmp/com.example.homebrew-upgrade.stderr</string>
|
|
<key>StandardOutPath</key>
|
|
<string>/tmp/com.example.homebrew-upgrade.stdout</string>
|
|
<key>StartCalendarInterval</key>
|
|
<array>
|
|
<dict>
|
|
<key>Hour</key>
|
|
<integer>8</integer>
|
|
</dict>
|
|
</array>
|
|
</dict>
|
|
</plist>
|
|
```
|
|
|
|
|
|
## License
|
|
|
|
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>.
|