Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Gadominas

macrumors newbie
Original poster
Dec 18, 2014
8
0
Be aware what is playing from your iTunes, Spotify or Rdio. Track the song title, album name on your OSX menubar.

In case you have your own music player which is not on the list it’s not an issue. You can update the scrip very easily to support your player as follow:
Code:
players=(iTunes Spotify Rdio)
replace to:
Code:
players=(iTunes Spotify Rdio MyNewPlayer)

Script can be player with ShellWrangler tool in order to track the song title/album on your OSX menubar.

Script to play:
Code:
#!/bin/bash

#   ____ __        __ __ _      __                       __         
#  / __// /  ___  / // /| | /| / /____ ___ _ ___  ___ _ / /___  ____
# _\ \ / _ \/ -_)/ // / | |/ |/ // __// _ `// _ \/ _ `// // -_)/ __/
#/___//_//_/\__//_//_/  |__/|__//_/   \_,_//_//_/\_, //_/ \__//_/   
#                                               /___/               
#
#   ___                     _  _____            _   
#  / __|  _ _ _ _ _ ___ _ _| ||_   _| _ __ _ __| |__
# | (_| || | '_| '_/ -_) ' \  _|| || '_/ _` / _| / /
#  \___\_,_|_| |_| \___|_||_\__||_||_| \__,_\__|_\_\
#                                                   
# Script author: gadominas@gmail.com   
#
#$$${ Be aware what is playing from your iTunes, Spotify and Rdio}
players=(iTunes Spotify Rdio)  
    
function empty {
    local var="$1"
    
    if test -z "$var"
    then
        [[ $( echo "1" ) ]]
        return

    # Return true if var is zero (0 as an integer or "0" as a string)
    elif [ "$var" == 0 2> /dev/null ]
    then
        [[ $( echo "1" ) ]]
        return

    # Return true if var is 0.0 (0 as a float)
    elif [ "$var" == 0.0 2> /dev/null ]
    then
        [[ $( echo "1" ) ]]
        return
    fi

    [[ $( echo "" ) ]]
}

function fetchActivePlayer() {
	for (( i = 0; i < ${#players[@]}; i++ )); do
		playerClient=$(osascript -e 'tell application "'${players[$i]}'" to if player state is playing then "'${players[$i]}'"' )

		if ! empty "$playerClient"
			then {
				echo "$playerClient"
				return
			}
		fi
	done
	
	echo ""
}


currentTrack() {
	# detect the player client name
	playerClient=$(fetchActivePlayer)
		
	# extract the metadata about the current track and show on menubar
	if empty "$playerClient" 
		then {
			printf "#"
		} else {
			currenTrack=$(osascript -e 'tell application "'$playerClient'" to if player state is playing then name of current track & "# " & artist of current track')

			if ! empty "$currenTrack"
				then {
					printf "#|$currenTrack"			
				} else
					printf "#"
			fi
		}
	fi			
}

run() {
	currentTrack
}

run
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.