Hello everyone,
I need a Spotify Now Playing widget with two lines that only works when Spotify is open. I took Aqua Touch's Spotify widget and edited it a bit, but since I don't know enough Apple Script, I couldn't make the song and artist appear below each other. If possible, I would also like to adjust the Song and Artist text size.
This is how the widget currently looks (playing and spotify not running states)
This is how I want it (playing and spotify not running states)
Here is code:
set haserror to false
tell application "BetterTouchTool"
if is_app_running "Spotify" then
try
tell application "Spotify"
try
--GET NAME AND ARTIST
set sName to (get name of current track)
set sArtist to (get artist of current track)
if sArtist is not "" then
set nowPlaying to sName & " - " & sArtist
else
set nowPlaying to sName
end if
--GET ARTWORK
set artworkURL to artwork url of current track
log artworkURL
--save artwork
set fileName to ((((path to application support folder from user domain) as text) & "BetterTouchTool:" as text) & "spotify_cover.png")
do shell script "curl " & artworkURL & " -o ~/Library/Application\\ Support/BetterTouchTool/spotify_cover.png"
--FIX JSON BREAKING STUFF----------------
set THESUBJECT to nowPlaying
--escape "\" via find replace to "\"
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to "\\"
set subject to text items of THESUBJECT
set text item delimiters of AppleScript to "\"
set THESUBJECT to subject as text
set text item delimiters of AppleScript to prevTIDs
-- Escape nasty JSON-breaking double quotes
set aString to THESUBJECT
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 THESUBJECT to aString
--output
set nowPlaying to THESUBJECT
--FIXED JSON BREAKING STUFF----------------
if player state is playing then
--RETURN
return "{\"text\":\"" & nowPlaying & "\",\"font_color\":\"255,255,255,255\",\"icon_path\":\"" & (POSIX path of fileName as text) & "\" }"
else
--display infomation while paused
return "{\"text\":\"" & nowPlaying & "\",\"font_color\":\"120,120,120,255\",\"icon_path\":\"" & (POSIX path of fileName as text) & "\" }"
--return returnText & " — Paused"
end if
on error
return "Spotify"
end try
end tell
on error
return "Spotify"
end try
else --end if open
return "Spotify"
end if
end tell
Additionally, when Spotify is not running, the widget turns into a Spotify button. If you can give me a hint about the code to make that invisible too, I would appreciate it!
Thank you!