# Improved Spotify Widget

**URL:** <https://community.folivora.ai/t/improved-spotify-widget/2752>\
**Category:** Setup/Preset Sharing\
**Tags:** touch-bar, widget\
**Created:** [August 4, 2018, 7:48am UTC](https://community.folivora.ai/t/improved-spotify-widget/2752 "2018-08-04T07:48:46Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![iAmWaldo](https://community.folivora.ai/letter_avatar_proxy/v4/letter/i/87869e/32.png) [@iAmWaldo](https://community.folivora.ai/u/iAmWaldo)\
**Post date:** [December 13, 2018, 7:25pm UTC](https://community.folivora.ai/t/improved-spotify-widget/2752/5 "2018-12-13T19:25:38Z")

</div>

Hey,

I have made some improvements to your script as it didn't seem to work when playing music offline...  
I also reworked the icon update as I noticed that with some artworks it was having trouble updating the icon (i noticed they took a bit longer to be added to the btt folder and therefore it would be take the artwork from the previous song) but now it works 100% of the time 🙂

```
on name_and_cover(trackName, iPath)
	tell application "BetterTouchTool"
		if iPath contains "offline" then
			update_touch_bar_widget "61E02114-40B8-4D7E-94D0-6F0110B7D846" text trackName
		else
			update_touch_bar_widget "61E02114-40B8-4D7E-94D0-6F0110B7D846" text trackName icon_path iPath
		end if
	end tell
end name_and_cover

set iconPath to "~/Library/Application Support/BetterTouchTool/spotify_cover.png"
if application "Spotify" is running then
	try
		tell application "Spotify"
			try
				set artworkURL to artwork url of current track
				do shell script "curl " & artworkURL & " -o ~/Library/Application\\ Support/BetterTouchTool/spotify_cover.png"
			on error number 6
				set iconPath to "offline"
			end try
			
			if player state is playing then
				set trackTitle to ((get name of current track) & " - " & (get artist of current track))
				if length of trackTitle is less than 27 then
					set displayTitle to trackTitle
					my name_and_cover(displayTitle, iconPath)
				else
					set displayTitle to text 1 thru 27 of trackTitle & "..."
					my name_and_cover(displayTitle, iconPath)
				end if
			else
				my name_and_cover("(Paused)", iconPath)
			end if
		end tell
	end try
else
	return ""
end if
```

---

_[View the full topic](https://community.folivora.ai/t/improved-spotify-widget/2752)._
