Skip to content

Instantly share code, notes, and snippets.

@jcromartie
Forked from anonymous/power.sh
Last active December 15, 2015 05:09
Show Gist options
  • Save jcromartie/5207403 to your computer and use it in GitHub Desktop.
Save jcromartie/5207403 to your computer and use it in GitHub Desktop.
#!/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 AC | grep "*"
}
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