Created
March 20, 2013 18:53
-
-
Save anonymous/5207390 to your computer and use it in GitHub Desktop.
Plays an audio file when power is connected
This file contains hidden or 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/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