mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-03-20 03:13:33 +01:00
parent
9724ff975f
commit
b66be3a580
1 changed files with 62 additions and 63 deletions
|
|
@ -144,25 +144,24 @@ function vncviewer() {
|
||||||
|
|
||||||
# iTunes control function
|
# iTunes control function
|
||||||
function itunes() {
|
function itunes() {
|
||||||
local opt=$1
|
local opt=$1
|
||||||
shift
|
shift
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
launch|play|pause|stop|rewind|resume|quit)
|
launch|play|pause|stop|rewind|resume|quit)
|
||||||
;;
|
;;
|
||||||
mute)
|
mute)
|
||||||
opt="set mute to true"
|
opt="set mute to true"
|
||||||
;;
|
;;
|
||||||
unmute)
|
unmute)
|
||||||
opt="set mute to false"
|
opt="set mute to false"
|
||||||
;;
|
;;
|
||||||
next|previous)
|
next|previous)
|
||||||
opt="$opt track"
|
opt="$opt track"
|
||||||
;;
|
;;
|
||||||
vol)
|
vol)
|
||||||
opt="set sound volume to $1" #$1 Due to the shift
|
opt="set sound volume to $1" #$1 Due to the shift
|
||||||
;;
|
;;
|
||||||
status|nowplaying)
|
status|nowplaying)
|
||||||
# Inspired by: http://hints.macworld.com/article.php?story=20011108211802830
|
|
||||||
local state=`osascript -e 'tell application "iTunes" to player state as string'`
|
local state=`osascript -e 'tell application "iTunes" to player state as string'`
|
||||||
echo "iTunes is currently $state"
|
echo "iTunes is currently $state"
|
||||||
if [ "$state" = "playing" ]; then
|
if [ "$state" = "playing" ]; then
|
||||||
|
|
@ -172,51 +171,51 @@ function itunes() {
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
shuf|shuff|shuffle)
|
shuf|shuff|shuffle)
|
||||||
# The shuffle property of current playlist can't be changed in iTunes 12,
|
# The shuffle property of current playlist can't be changed in iTunes 12,
|
||||||
# so this workaround uses AppleScript to simulate user input instead.
|
# so this workaround uses AppleScript to simulate user input instead.
|
||||||
# Defaults to toggling when no options are given.
|
# Defaults to toggling when no options are given.
|
||||||
# The toggle option depends on the shuffle button being visible in the Now playing area.
|
# The toggle option depends on the shuffle button being visible in the Now playing area.
|
||||||
# On and off use the menu bar items.
|
# On and off use the menu bar items.
|
||||||
local state=$1
|
local state=$1
|
||||||
|
|
||||||
if [[ -n "$state" && ! "$state" =~ "^(on|off|toggle)$" ]]
|
if [[ -n "$state" && ! "$state" =~ "^(on|off|toggle)$" ]]
|
||||||
then
|
then
|
||||||
print "Usage: itunes shuffle [on|off|toggle]. Invalid option."
|
print "Usage: itunes shuffle [on|off|toggle]. Invalid option."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$state" in
|
case "$state" in
|
||||||
on|off)
|
on|off)
|
||||||
# Inspired by: http://stackoverflow.com/a/14675583
|
# Inspired by: http://stackoverflow.com/a/14675583
|
||||||
osascript 1>/dev/null 2>&1 <<-EOF
|
osascript 1>/dev/null 2>&1 <<-EOF
|
||||||
tell application "System Events" to perform action "AXPress" of (menu item "${state}" of menu "Shuffle" of menu item "Shuffle" of menu "Controls" of menu bar item "Controls" of menu bar 1 of application process "iTunes" )
|
tell application "System Events" to perform action "AXPress" of (menu item "${state}" of menu "Shuffle" of menu item "Shuffle" of menu "Controls" of menu bar item "Controls" of menu bar 1 of application process "iTunes" )
|
||||||
EOF
|
EOF
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
toggle|*)
|
toggle|*)
|
||||||
osascript 1>/dev/null 2>&1 <<-EOF
|
osascript 1>/dev/null 2>&1 <<-EOF
|
||||||
tell application "System Events" to perform action "AXPress" of (button 2 of process "iTunes"'s window "iTunes"'s scroll area 1)
|
tell application "System Events" to perform action "AXPress" of (button 2 of process "iTunes"'s window "iTunes"'s scroll area 1)
|
||||||
EOF
|
EOF
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
""|-h|--help)
|
""|-h|--help)
|
||||||
echo "Usage: itunes <option>"
|
echo "Usage: itunes <option>"
|
||||||
echo "option:"
|
echo "option:"
|
||||||
echo "\tlaunch|play|pause|stop|rewind|resume|quit"
|
echo "\tlaunch|play|pause|stop|rewind|resume|quit"
|
||||||
echo "\tmute|unmute\tcontrol volume set"
|
echo "\tmute|unmute\tcontrol volume set"
|
||||||
echo "\tnext|previous\tplay next or previous track"
|
echo "\tnext|previous\tplay next or previous track"
|
||||||
echo "\tshuf|shuffle [on|off|toggle]\tSet shuffled playback. Default: toggle. Note: toggle doesn't support the MiniPlayer."
|
echo "\tshuf|shuffle [on|off|toggle]\tSet shuffled playback. Default: toggle. Note: toggle doesn't support the MiniPlayer."
|
||||||
echo "\tvol\tSet the volume, takes an argument from 0 to 100"
|
echo "\tvol\tSet the volume, takes an argument from 0 to 100"
|
||||||
echo "\thelp\tshow this message and exit"
|
echo "\thelp\tshow this message and exit"
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
print "Unknown option: $opt"
|
print "Unknown option: $opt"
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
osascript -e "tell application \"iTunes\" to $opt"
|
osascript -e "tell application \"iTunes\" to $opt"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue