$ media [TAB] [TAB]
pause play skip volume
$ media play [TAB] [TAB]
itunes spotify
$ media pause [TAB] [TAB]
itunes spotify
$ media skip [TAB] [TAB]
itunes spotify
$ media volume [RETURN]
output volume:20, input volume:100, alert volume:100, output muted:false
$ media volume [TAB] [TAB]
down up
$ media volume up 10 [RETURN]
output volume:30, input volume:100, alert volume:100, output muted:false
$ media volume down 10 [RETURN]
output volume:20, input volume:100, alert volume:100, output muted:false
Last active
August 29, 2015 14:02
-
-
Save kates/4c968f9ecca8fd419e90 to your computer and use it in GitHub Desktop.
controlling media in macosx terminal
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
#!/usr/bin/env bash | |
current_volume() | |
{ | |
VOL=$(osascript -e "get volume settings" | awk '/output volume/ { print substr($2, 8, index($2, ",") - index($2, ":") - 1); }') | |
} | |
volume() | |
{ | |
case "$LEVEL" in | |
up) | |
current_volume | |
if [ $INC ]; then | |
VOL=$VOL+$INC | |
else | |
VOL=$VOL+1 | |
fi | |
;; | |
down) | |
current_volume | |
if [ $INC ]; then | |
VOL=$VOL-$INC | |
else | |
VOL=$VOL-1 | |
fi | |
;; | |
esac | |
if [ $VOL ]; then | |
osascript -e "set volume output volume ${VOL}" | |
fi | |
osascript -e "get volume settings" | |
} | |
case "$1" in | |
v|vol|volume) | |
LEVEL=$2 | |
INC=$3 | |
volume | |
;; | |
play|start) | |
SOURCE=$2 | |
if [ $SOURCE ]; then | |
osascript -e "tell application \"${SOURCE}\" to play" | |
fi | |
;; | |
skip) | |
SOURCE=$2 | |
if [ $SOURCE ]; then | |
osascript -e "tell application \"${SOURCE}\" to play next track" | |
fi | |
;; | |
pause|stop) | |
SOURCE=$2 | |
if [ $SOURCE ]; then | |
osascript -e "tell application \"${SOURCE}\" to pause" | |
fi | |
;; | |
*) | |
echo "Usage: media ACTION [OPTION [VALUE]]" | |
;; | |
esac |
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
_media() | |
{ | |
cur=${COMP_WORDS[COMP_CWORD]} | |
prev=${COMP_WORDS[COMP_CWORD-1]} | |
case "${prev}" in | |
play|pause|skip) | |
COMPREPLY=( $(compgen -W "spotify itunes" -- $cur) ) | |
;; | |
volume) | |
COMPREPLY=( $(compgen -W "up down" -- $cur) ) | |
;; | |
up|down) | |
;; | |
*) | |
COMPREPLY=( $(compgen -W "pause play skip volume" -- $cur) ) | |
;; | |
esac | |
} | |
complete -F _media media |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment