d874c73f19d8430f4dc32756fff0bf2f6a804d87

Author
Avi Israeli <avii@wix.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

itunes playlist first commit (#5860)

Added playlist feature for the itunes command: 
if a variable is passed and is valid - will play the playlist
if a variable is passed and is invalid(no such playlist) - will stop all playing
if no variable is passed will print all playlists available on the host

Diff

 1diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh
 2index 95ef3e1aa75d0ee7109cd0b8a006da0913710c9f..e8488ebc94ab5b7cb521b6685dd4f7c5111365ef 100644
 3--- a/plugins/osx/osx.plugin.zsh
 4+++ b/plugins/osx/osx.plugin.zsh
 5@@ -184,6 +184,7 @@ function vncviewer() {
 6 # iTunes control function
 7 function itunes() {
 8 	local opt=$1
 9+	local playlist=$2
10 	shift
11 	case "$opt" in
12 		launch|play|pause|stop|rewind|resume|quit)
13@@ -200,6 +201,19 @@ function itunes() {
14 		vol)
15 			opt="set sound volume to $1" #$1 Due to the shift
16 			;;
17+		playlist)
18+		# Inspired by: https://gist.github.com/nakajijapan/ac8b45371064ae98ea7f
19+if [[ ! -z "$playlist" ]]; then
20+                    		osascript -e 'tell application "iTunes"' -e "set new_playlist to \"$playlist\" as string" -e "play playlist new_playlist" -e "end tell" 2>/dev/null;
21+				if [[ $? -eq 0 ]]; then
22+					opt="play"
23+				else
24+					opt="stop"
25+				fi	
26+                  else
27+                    opt="set allPlaylists to (get name of every playlist)"
28+                  fi
29+                ;;
30 		playing|status)
31 			local state=`osascript -e 'tell application "iTunes" to player state as string'`
32 			if [[ "$state" = "playing" ]]; then
33@@ -250,6 +264,7 @@ EOF
34 			echo "\tshuf|shuffle [on|off|toggle]\tSet shuffled playback. Default: toggle. Note: toggle doesn't support the MiniPlayer."
35 			echo "\tvol\tSet the volume, takes an argument from 0 to 100"
36 			echo "\tplaying|status\tShow what song is currently playing in iTunes."
37+			echo "\tplaylist [playlist name]\t Play specific playlist"
38 			echo "\thelp\tshow this message and exit"
39 			return 0
40 			;;