From a746e6010ae2b260213f081789eaff01865f5664 Mon Sep 17 00:00:00 2001 From: Andy Bateman Date: Mon, 14 Sep 2015 19:27:41 +1200 Subject: [PATCH 1/5] Update osx.plugin.zsh Added function to display the song you're currently listening to in iTunes Fixed indent Indentation on line 169 was squiffy Fixed spelling Removed unnecessary wording to make function more succinct. Highlighting of Artist and Track Changed the highlighting of the Track and Artist in yellow to make use of Prompt Expansion Colors --- 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 390960fd..044276c1 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -161,6 +161,15 @@ function itunes() { vol) opt="set sound volume to $1" #$1 Due to the shift ;; + playing) + local state=`osascript -e 'tell application "iTunes" to player state as string'` + if [ "$state" = "playing" ]; then + currenttrack=`osascript -e 'tell application "iTunes" to name of current track as string'` + currentartist=`osascript -e 'tell application "iTunes" to artist of current track as string'` + echo "Listening to %F{yellow}$currenttrack%f by %F{yellow}$currentartist%f"; + 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. @@ -199,6 +208,7 @@ EOF 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 "\tvol\tSet the volume, takes an argument from 0 to 100" + echo "\tplaying\tShow what song is currently playing in iTunes." echo "\thelp\tshow this message and exit" return 0 ;; From 29db0e0119aba4f317ac320ed5089b82142bcb10 Mon Sep 17 00:00:00 2001 From: Andy Bateman Date: Thu, 17 Sep 2015 13:48:30 +1200 Subject: [PATCH 2/5] Fixed colourisation of Now Playing function --- plugins/osx/osx.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh index 044276c1..f1b43718 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -166,7 +166,7 @@ function itunes() { if [ "$state" = "playing" ]; then currenttrack=`osascript -e 'tell application "iTunes" to name of current track as string'` currentartist=`osascript -e 'tell application "iTunes" to artist of current track as string'` - echo "Listening to %F{yellow}$currenttrack%f by %F{yellow}$currentartist%f"; + print -P "Listening to %F{yellow}$currenttrack%f by %F{yellow}$currentartist%f"; fi return 0 ;; From 9f2acdc445f05e6556cf6180a1edd52b6939bbcc Mon Sep 17 00:00:00 2001 From: Andy Bateman Date: Thu, 17 Sep 2015 18:28:48 +1200 Subject: [PATCH 3/5] You can now use 'itunes status' as well as 'itunes playing' to show current track --- plugins/osx/osx.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh index f1b43718..859e08da 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -161,9 +161,9 @@ function itunes() { vol) opt="set sound volume to $1" #$1 Due to the shift ;; - playing) + playing|status) local state=`osascript -e 'tell application "iTunes" to player state as string'` - if [ "$state" = "playing" ]; then + if [[ "$state" = "playing" ]]; then currenttrack=`osascript -e 'tell application "iTunes" to name of current track as string'` currentartist=`osascript -e 'tell application "iTunes" to artist of current track as string'` print -P "Listening to %F{yellow}$currenttrack%f by %F{yellow}$currentartist%f"; From 993e09cc6b6127be92afe072f5957e4e9e72367f Mon Sep 17 00:00:00 2001 From: Andy Bateman Date: Thu, 17 Sep 2015 19:12:35 +1200 Subject: [PATCH 4/5] Added function for 'itunes playing' to display state when not playing --- plugins/osx/osx.plugin.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh index 859e08da..9413f505 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -167,6 +167,8 @@ function itunes() { currenttrack=`osascript -e 'tell application "iTunes" to name of current track as string'` currentartist=`osascript -e 'tell application "iTunes" to artist of current track as string'` print -P "Listening to %F{yellow}$currenttrack%f by %F{yellow}$currentartist%f"; + else + print "iTunes is" $state; fi return 0 ;; @@ -208,7 +210,7 @@ EOF 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 "\tvol\tSet the volume, takes an argument from 0 to 100" - echo "\tplaying\tShow what song is currently playing in iTunes." + echo "\tplaying|status\tShow what song is currently playing in iTunes." echo "\thelp\tshow this message and exit" return 0 ;; From 326c2b08593e9b02da149dcc0d3c5cf99b21d3a2 Mon Sep 17 00:00:00 2001 From: Andy Bateman Date: Sun, 20 Sep 2015 08:46:45 +1200 Subject: [PATCH 5/5] Replaced the use of 'print' with 'echo' in order to sanitise track and artist names Fixed indentation Fixed indentation --- plugins/osx/osx.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh index 9413f505..86778363 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -166,9 +166,9 @@ function itunes() { if [[ "$state" = "playing" ]]; then currenttrack=`osascript -e 'tell application "iTunes" to name of current track as string'` currentartist=`osascript -e 'tell application "iTunes" to artist of current track as string'` - print -P "Listening to %F{yellow}$currenttrack%f by %F{yellow}$currentartist%f"; + echo -E "Listening to $fg[yellow]$currenttrack$reset_color by $fg[yellow]$currentartist$reset_color"; else - print "iTunes is" $state; + echo "iTunes is" $state; fi return 0 ;;