Now playing widget on menu bar

How can I have a now playing widget for Spotify on the menu bar?
Thanks

If you have one for the Touch Bar, just copy-paste the Apple-/Javascript in a menu bar widget. They work the same way.

1 Like

that worked, but the name only shown when it is highlighted (when I click and hold it)

Refresh rate is good?

Would you mind pasting the script below?

I put refresh rate to 0.1 seconds just for the testing, will change to 0.5 or 1 later.
script:

tell application "BetterTouchTool"
if is_app_running "Spotify" then
	tell application "Spotify"
		try
			if player state is playing then
				set sName to (get name of current track)
				set sArtist to (get artist of current track)
				
				if (length of sName) > 25 then
					set sName to text 1 thru 22 of sName & "..."
				else
					set sName to (get name of current track)
				end if
				if (length of sArtist) > 25 then
					set sArtist to text 1 thru 22 of sArtist & "..."
				else
					set sArtist to (get artist of current track)
				end if
				if sArtist is not "" then
					set nowPlaying to sName & "  —  " & sArtist
				else
					set nowPlaying to sName
				end if
				
				--fix JSON-Breaking Double Quotes
				set aString to nowPlaying
				set astid to AppleScript's text item delimiters
				set AppleScript's text item delimiters to quote
				set aString to text items of aString
				set AppleScript's text item delimiters to "\\" & quote
				set aString to aString as text
				set AppleScript's text item delimiters to astid
				-- Quotes have been vanquished
				set nowPlaying to aString
				
				set artworkURL to artwork url of current track
				
				set fileName to ((((path to application support folder from user domain) as text) & "BetterTouchTool:" as text) & "spotify_cover.png")
				
				set sNamePlist to ""
				set sArtistPlist to ""
				set plistfile_path to ((((path to application support folder from user domain) as text) & "BetterTouchTool:" as text) & "spotify_playing.plist")
				
				set returnText to "{\"text\":\"" & nowPlaying & "\",\"font_color\": \"255,255,255,255\", \"icon_path\":\"" & (POSIX path of fileName as text) & "\" }"
				
				-- read the plist file
				tell application "System Events"
					try
						if file plistfile_path exists then
							tell property list file plistfile_path
								tell contents
									set sNamePlist to value of property list item "sName"
									set sArtistPlist to value of property list item "sArtist"
								end tell
							end tell
						end if
						if (sName is sNamePlist) and (sArtist is sArtistPlist) then
							--return "Found it!"
							tell application "BetterTouchTool" to set_string_variable "ShowNotPlayingMsg1" to "false"
							return returnText
							
						end if
					on error
						tell application "BetterTouchTool" to set_string_variable "ShowNotPlayingMsg1" to "true"
						return "{\"text\":\" Spotify \",\"font_color\": \"255,255,255,255\"}"
					end try
				end tell
				
				if (sName is not sNamePlist) or (sArtist is not sArtistPlist) then
					
					tell application "System Events"
						try
							-- create an empty property list dictionary item
							set the parent_dictionary to make new property list item with properties {kind:record}
							
							-- create new property list file using the empty dictionary list item as contents
							set this_plistfile to ¬
								make new property list file with properties {contents:parent_dictionary, name:plistfile_path}
							make new property list item at end of property list items of contents of this_plistfile ¬
								with properties {kind:string, name:"sName", value:sName}
							make new property list item at end of property list items of contents of this_plistfile ¬
								with properties {kind:string, name:"sArtist", value:sArtist}
						on error
							tell application "BetterTouchTool" to set_string_variable "ShowNotPlayingMsg1" to "true"
							return "{\"text\":\" Spotify \",\"font_color\": \"255,255,255,255\"}"
						end try
					end tell
					
					do shell script "curl " & artworkURL & " -o ~/Library/Application\\ Support/BetterTouchTool/spotify_cover.png"
					
					tell application "BetterTouchTool" to set_string_variable "ShowNotPlayingMsg1" to "false"
					return returnText
					
				end if
			else
				tell application "BetterTouchTool" to set_string_variable "ShowNotPlayingMsg1" to "false"
				return "{\"text\":\" Spotify \",\"font_color\": \"255,255,255,255\"}"
			end if
		on error
			tell application "BetterTouchTool" to set_string_variable "ShowNotPlayingMsg1" to "false"
			return "{\"text\":\" Spotify \",\"font_color\": \"255,255,255,255\"}"
		end try
	end tell
else
	tell application "BetterTouchTool" to set_string_variable "ShowNotPlayingMsg1" to "true"
	return ""
end if

end tell

also, this only works for Spotify now playing. is there something I can use that you have that will work for any now playing?

Imprint | Privacy Policy