Skip to content

Instantly share code, notes, and snippets.

@tjluoma
Created May 23, 2014 18:52
Show Gist options
  • Save tjluoma/05ec116d965bc399fa07 to your computer and use it in GitHub Desktop.
Save tjluoma/05ec116d965bc399fa07 to your computer and use it in GitHub Desktop.
If Caffeine is off: launch it, and tell user how long Caffeine will run for. If Caffeine is on, quit it.
tell application "System Events"
if exists (process "Caffeine") then
tell application "Caffeine"
if active is false then
turn on
do shell script "DURATION=`defaults read com.lightheadsw.caffeine.plist DefaultDuration`
if [ \"$DURATION\" = \"0\" ]
then
DURATION='Will run until quit'
else
DURATION=\"Will remain on for $DURATION minutes\"
fi
growlnotify --appIcon 'Caffeine' --identifier 'CaffeineStatus' --message \"$DURATION\" --title 'Caffeine Now On'"
else
do shell script "growlnotify --appIcon 'Caffeine' --identifier 'CaffeineStatus' --message 'via Keyboard Maestro' --title 'Caffeine Now Off'"
quit
end if
end tell
else
tell application "Caffeine" to run
do shell script "ACTIVATE_ON_LAUNCH=`defaults read com.lightheadsw.caffeine.plist ActivateOnLaunch`
if [ \"$ACTIVATE_ON_LAUNCH\" = \"0\" ]
then
####
growlnotify --appIcon 'Caffeine' --identifier 'CaffeineStatus' --message 'set Activate on Launch to change behavior'
--title 'Caffeine.app running,
but inactive'
####
else
DURATION=`defaults read com.lightheadsw.caffeine.plist DefaultDuration`
if [ \"$DURATION\" = \"0\" ]
then
DURATION='Will run until quit'
else
DURATION=\"Will remain on for $DURATION minutes\"
fi
growlnotify --appIcon 'Caffeine' --identifier 'CaffeineStatus' --message \"$DURATION\" --title 'Caffeine Now On'
fi
"
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment