Skip to content

Instantly share code, notes, and snippets.

@whs
Created August 12, 2014 02:21
Show Gist options
  • Save whs/651fe6b045e5c7b5cc67 to your computer and use it in GitHub Desktop.
Save whs/651fe6b045e5c7b5cc67 to your computer and use it in GitHub Desktop.
Inhibit power management and alarm if power is off
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
@dtinth
Copy link

dtinth commented Aug 12, 2014

The set Volume N is deprecated, better use set volume output volume M where M is in percentage.

Here is a function to run say with full volume.

#!/bin/bash

loud_say() {
  OLD_VOLUME=`osascript -e "output volume of (get volume settings)"`
  osascript -e "set volume output volume 100"
  say "$@"
  osascript -e "set volume output volume $OLD_VOLUME"
}

loud_say -v Kanya ทดสอบ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment