Skip to content

Instantly share code, notes, and snippets.

@amashigeseiji
Last active August 29, 2015 14:08
Show Gist options
  • Save amashigeseiji/d6ed72ccd08ba1b904f6 to your computer and use it in GitHub Desktop.
Save amashigeseiji/d6ed72ccd08ba1b904f6 to your computer and use it in GitHub Desktop.
Mac でコマンドラインからボリュームをコントロールする
#!/bin/bash
current=$(osascript -e "output volume of (get volume settings)")
if [ ${#@} -eq 0 ];then
echo "current volume: $current"
exit
fi
set=$current
num=10
function getnum {
local digit=$(expr $1 : '[0-9]*')
if [ $digit -gt 0 -a $digit -lt 4 ];then
if [ $1 -lt 101 ];then
num=$1
fi
else
echo 'invalid argument';exit;
fi
echo $num
}
if [ $1 = 'up' ];then
if [ ${#@} -gt 1 ];then
num=$(getnum $2)
fi
set=$(expr $current + $num)
elif [ $1 = 'down' ];then
if [ ${#@} -gt 1 ];then
num=$(getnum $2)
fi
set=$(expr $current - $num)
elif [ $1 = 'mute' ];then
set=0
elif [ $(expr $1 : '[0-9]*') ];then
set=$1
else echo 'invalid argument';exit;
fi
osascript -e "set Volume output volume $set"
echo "set volume $set"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment