Last active
August 29, 2015 14:15
-
-
Save tjluoma/ad43de5abf3e6a657175 to your computer and use it in GitHub Desktop.
Example shell script to be used with IFTTT and 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
#!/bin/zsh -f | |
# Important! DIR _must_ be the same as whatever directory you used | |
# for `QueueDirectories` in the `com.tjluoma.ignitiononoroffatwork.plist` | |
DIR="/Users/jsmyth/Dropbox/IFTTT/Automatic/IgnitionOnOrOffAtWork/" | |
# if the directory does not exist, exit | |
cd "$DIR" || exit 0 | |
# get rid of this file, which will cause `launchd` to keep triggering | |
rm -f .DS_Store | |
command ls -1 \ | |
| egrep 'IgnitionOn|IgnitionOff' \ | |
| while read line | |
do | |
case "$line" in | |
IgnitionOn*) | |
########################################################################### | |
## BEGIN OPTIONAL SECTION for when Ignition is turned on | |
## Change this in this section to suit your needs | |
# run BitTorrent Sync application | |
open -a 'BitTorrent Sync' | |
# mount TimeMachine drive, if not mounted | |
[[ ! -d '/Volumes/TimeMachine' ]] && diskutil mount TimeMachine | |
if (( $+commands[lock.sh] )) | |
then | |
# if the 'lock.sh' script is found, run it | |
lock.sh | |
else | |
# otherwise, just lock screen by switching to login window | |
'/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession' -suspend | |
fi | |
## END OPTIONAL SECTION for when Ignition is turned on | |
########################################################################### | |
# This deletes the file so that launchd doesn't just keep triggering the script | |
rm -f "$line" | |
;; | |
IgnitionOff*) | |
########################################################################### | |
## BEGIN OPTIONAL SECTION for when Ignition is turned off | |
## Change this in this section to suit your needs | |
# launch apps that you want to have run when you get to the office | |
# these are just some examples | |
open -g -a 'OmniFocus' | |
open -g -a 'BusyCal' | |
open -g -a 'MailMate' | |
## END OPTIONAL SECTION for when Ignition is turned off | |
########################################################################### | |
# This deletes the file so that launchd doesn't just keep triggering the script | |
rm -f "$line" | |
;; | |
esac | |
done | |
exit 0 | |
# End Of File |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also: https://gist.github.com/tjluoma/c761e592a9fb435a6e93