Created
August 12, 2014 02:21
-
-
Save whs/651fe6b045e5c7b5cc67 to your computer and use it in GitHub Desktop.
Inhibit power management and alarm if power is off
This file contains 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
isAC(){ | |
pmset -g batt | grep AC > /dev/null | |
} | |
TXT=$* | |
if [ "$TXT" = "" ] | |
then | |
TXT="อย่าปิดปลั๊ก" | |
fi | |
POWERON=1 | |
trap 'kill $(jobs -p);echo Stopped inhibiting power management' EXIT | |
caffeinate -i & | |
echo "Inhibited power management" | |
while true | |
do | |
while isAC | |
do | |
if [ "$POWERON" = 0 ] | |
then | |
echo "Power engaged on" `date` | |
POWERON=1 | |
fi | |
sleep 1 | |
done | |
if [ "$POWERON" = 1 ]; | |
then | |
echo "Power disengaged on" `date` | |
POWERON=0 | |
fi | |
osascript -e "set Volume 10" | |
say -v Kanya $TXT | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
set Volume N
is deprecated, better useset volume output volume M
where M is in percentage.Here is a function to run
say
with full volume.