Skip to content

Instantly share code, notes, and snippets.

Created March 20, 2013 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/5207390 to your computer and use it in GitHub Desktop.
Save anonymous/5207390 to your computer and use it in GitHub Desktop.
Plays an audio file when power is connected
#!/bin/bash
# Please supply your own audio file...
audiofile="$1"
if [[ ! -f "$audiofile" ]]
then
echo "USAGE: $(basename ${0}) audio_file"
exit 1
fi
function getPowerState {
pmset -g | grep "*" | grep AC
}
last=$(getPowerState)
while true
do
next=$(getPowerState)
if [[ -z "$last" && -n "$next" ]]
then
afplay $audiofile
fi
sleep 2
last="$next"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment