From a1e0ca9c88dacf51bd208b7cc6e49f3f5d05ebef Mon Sep 17 00:00:00 2001 From: Ian Walker Date: Mon, 15 Jun 2015 22:13:48 +0900 Subject: [PATCH 1/6] Added itunes status command --- plugins/osx/osx.plugin.zsh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh index a6e3a83e6..e407404a6 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -161,6 +161,16 @@ function itunes() { vol) opt="set sound volume to $1" #$1 Due to the shift ;; + status) + its_status=`osascript -e 'tell application "iTunes" to player state as string'` + echo "iTunes is currently $its_status" + if [ "$its_status" = "playing" ]; then + artist=`osascript -e 'tell application "iTunes" to artist of current track as string'` + track=`osascript -e 'tell application "iTunes" to name of current track as string'` + echo "Current track: $artist / $track"; + fi + return 0 + ;; shuf|shuff|shuffle) # The shuffle property of current playlist can't be changed in iTunes 12, # so this workaround uses AppleScript to simulate user input instead. From 65708708284a2bbf047dd198fd7e0ee051505d6b Mon Sep 17 00:00:00 2001 From: Ian Walker Date: Mon, 15 Jun 2015 22:21:00 +0900 Subject: [PATCH 2/6] Cleaned up the code a bit --- plugins/osx/osx.plugin.zsh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh index e407404a6..9f0487051 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -161,10 +161,10 @@ function itunes() { vol) opt="set sound volume to $1" #$1 Due to the shift ;; - status) - its_status=`osascript -e 'tell application "iTunes" to player state as string'` - echo "iTunes is currently $its_status" - if [ "$its_status" = "playing" ]; then + status|nowplaying) + local state=`osascript -e 'tell application "iTunes" to player state as string'` + echo "iTunes is currently $state" + if [ "$state" = "playing" ]; then artist=`osascript -e 'tell application "iTunes" to artist of current track as string'` track=`osascript -e 'tell application "iTunes" to name of current track as string'` echo "Current track: $artist / $track"; From 9724ff975f9b1fcf326c25685783d24aef4b1647 Mon Sep 17 00:00:00 2001 From: Ian Walker Date: Mon, 15 Jun 2015 22:22:53 +0900 Subject: [PATCH 3/6] Fixed tab/spaces --- plugins/osx/osx.plugin.zsh | 121 +++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 60 deletions(-) diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh index 9f0487051..840f7eb00 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -144,24 +144,25 @@ function vncviewer() { # iTunes control function function itunes() { - local opt=$1 - shift - case "$opt" in - launch|play|pause|stop|rewind|resume|quit) - ;; - mute) - opt="set mute to true" - ;; - unmute) - opt="set mute to false" - ;; - next|previous) - opt="$opt track" - ;; - vol) - opt="set sound volume to $1" #$1 Due to the shift - ;; + local opt=$1 + shift + case "$opt" in + launch|play|pause|stop|rewind|resume|quit) + ;; + mute) + opt="set mute to true" + ;; + unmute) + opt="set mute to false" + ;; + next|previous) + opt="$opt track" + ;; + vol) + opt="set sound volume to $1" #$1 Due to the shift + ;; status|nowplaying) + # Inspired by: http://hints.macworld.com/article.php?story=20011108211802830 local state=`osascript -e 'tell application "iTunes" to player state as string'` echo "iTunes is currently $state" if [ "$state" = "playing" ]; then @@ -171,51 +172,51 @@ function itunes() { fi return 0 ;; - shuf|shuff|shuffle) - # The shuffle property of current playlist can't be changed in iTunes 12, - # so this workaround uses AppleScript to simulate user input instead. - # Defaults to toggling when no options are given. - # The toggle option depends on the shuffle button being visible in the Now playing area. - # On and off use the menu bar items. - local state=$1 + shuf|shuff|shuffle) + # The shuffle property of current playlist can't be changed in iTunes 12, + # so this workaround uses AppleScript to simulate user input instead. + # Defaults to toggling when no options are given. + # The toggle option depends on the shuffle button being visible in the Now playing area. + # On and off use the menu bar items. + local state=$1 - if [[ -n "$state" && ! "$state" =~ "^(on|off|toggle)$" ]] - then - print "Usage: itunes shuffle [on|off|toggle]. Invalid option." - return 1 - fi + if [[ -n "$state" && ! "$state" =~ "^(on|off|toggle)$" ]] + then + print "Usage: itunes shuffle [on|off|toggle]. Invalid option." + return 1 + fi - case "$state" in - on|off) - # Inspired by: http://stackoverflow.com/a/14675583 - 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" ) + case "$state" in + on|off) + # Inspired by: http://stackoverflow.com/a/14675583 + 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" ) EOF - return 0 - ;; - toggle|*) - 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) + return 0 + ;; + toggle|*) + 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) EOF - return 0 - ;; - esac - ;; - ""|-h|--help) - echo "Usage: itunes