Display iTunes Cover & Currently Playing Track

@GoldenChaos I haven't faced issues with Spotify, although it for some reason has converted Spotify to Spotify (Old) in my script? Then again the Spotify app has changed to Spotify (Old) for me too. Not sure what's happened. I rarely use Spotify though so hard to comment on.

I did come across an issue with iTunes if you use Apple Music. As the artwork is streamed it creates some issues searching for it. I was able to fix by checking if an artwork is available first though. Full iTunes code can be seen here:

if application "iTunes" is running then
	tell application "iTunes" to tell current track
		if exists (every artwork) then
			tell artwork 1
				set srcBytes to raw data
				-- figure out the proper file extension
				if format is «class PNG » then
					set ext to ".png"
				else
					set ext to ".jpg"
				end if
			end tell
			set fileName to ((((path to application support folder from user domain) as text) & "BetterTouchTool:" as text) & "itunes_cover" & ext)
			-- write to file
			set outFile to open for access file fileName with write permission
			-- truncate the file
			set eof outFile to 0
			-- write the image bytes to the file
			write srcBytes to outFile
			close access outFile
		else
			set fileName to ((((path to application support folder from user domain) as text) & "BetterTouchTool:" as text) & "itunes.png")
		end if
	end tell
	set maxSize to 25
	tell application "iTunes"
		set playState to (player state as text)
		if playState is equal to "playing" then
			set trackName to name of current track
			set artistName to artist of current track
			set albumName to album of current track
			if length of trackName is greater than maxSize then
				set trackName to text 1 thru (maxSize - 3) of trackName & "..."
			end if
			if length of artistName is greater than maxSize then
				set artistName to text 1 thru (maxSize - 3) of artistName & "..."
			end if
			set trackInfo to trackName & " | " & artistName
		else
			set trackInfo to ""
		end if
		return "{\"text\":\"" & trackInfo & "\", \"icon_path\":\"" & (POSIX path of fileName as text) & "\"}"
	end tell
end if
1 Like