Is someone able to make this code work for any media playing, not just spotify? (Netflix, youtube, apple music, etc)
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
--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
tell application "BetterTouchTool" to set_string_variable "ShowNotPlayingMsg1" to "false"
return "{\"text\":\"" & nowPlaying & "\",\"font_color\":\"255,255,255,255\",\"icon_path\":\"" & (POSIX path of fileName as text) & "\" }"
else
--display infomation while paused
tell application "BetterTouchTool" to set_string_variable "ShowNotPlayingMsg1" to "false"
return "{\"text\":\"" & nowPlaying & "\",\"font_color\":\"255,255,255,127\",\"icon_path\":\"" & (POSIX path of fileName as text) & "\" }"
--return returnText & " — Paused"
end if
on error
tell application "BetterTouchTool" to set_string_variable "ShowNotPlayingMsg1" to "true"
return "{\"text\":\"Spotify\",\"font_color\":\"255,255,255,127\" }"
end try
end tell
on error
tell application "BetterTouchTool" to set_string_variable "ShowNotPlayingMsg1" to "true"
return "Spotify"
end try
else --end if open
tell application "BetterTouchTool" to set_string_variable "ShowNotPlayingMsg1" to "true"
return ""
end if
end tell