Skip to content

Instantly share code, notes, and snippets.

@tjluoma
Last active August 29, 2015 14:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjluoma/ad43de5abf3e6a657175 to your computer and use it in GitHub Desktop.
Save tjluoma/ad43de5abf3e6a657175 to your computer and use it in GitHub Desktop.
Example shell script to be used with IFTTT and launchd
#!/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
@tjluoma
Copy link
Author

tjluoma commented Feb 12, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment