Display the currently playing track in iTunes/Spotify on the Touch Bar

Ever since I got my 2016 15″ MacBook Pro with Touch Bar, I wanted to have it show one thing: the currently playing track. Today, thanks to the amazing Better Touch Tool and some Apple Script (which I don’t like, but it gets the job done), I finally have that functionality.

It’s really easy:

  1. Open Better Touch Tool and click on the Touch Bar section.
  2. Add a widget and select the “Run Apple Script and Show Return Value” option.
  3. Click on the “Advanced Configuration” button and paste the relevant Apple Script (see below).
  4. Optional: set the Predefined Action to “Open Application / File / Apple Script …” and select iTunes/Spotify: this will always bring iTunes/Spotiy to the foreground when you tap the widget.
  5. Optional: set the iTunes/Spotify icon as the widget’s icon (You can right click on the .app bundle, click on “Show Package Contents”, then go to Contents/Resources. The icones are respectively iTunes.icns and Icon.icns, just drag them over their spot in BTT.)

Here is the script for iTunes:

And here is the one for Spotiy:

The only difference between the two is the name of the app in the first if and in the tell statement.

Better Touch Tool hides the widget if the Apple Script returns nothing (which is the case when the music is paused or when the iTunes/Spotify are closed): you can work that around by replacing the two return "" with return " ", i.e. returning a space when nothing is playing. It’s not very aesthetically pleasing on the Touch Bar because the button is asymmetric, but you can do that if you prefer it that way.

33 thoughts on “Display the currently playing track in iTunes/Spotify on the Touch Bar

  1. Grazie per gli ottimi script…. D’altronde bisogna aggiustarsi con BTT dal momento che praticamente nessuna App si sta adattando alla nuova TB…

  2. Pingback: EasyApple #297: L'utilizzatore di giga - EasyPodcast

  3. Great tip.

    If I press the cross to the left of the widget, it disappears. I find that I have to go into “advanced configuration” and press save, then it’s back.

    Is there a better way of restoring the widget if closed? Or perhaps set it up permanently?

    • That’s a feature of BTT, as it allows you to dismiss its custom Touch Bar to reveal the system/app one. You can however define a shortcut in BTT that launches the action “Toggle BetterTouchTool Touch Bar” to quickly show/hide it.

  4. Pingback: How to display iTunes or Spotify now playing on a Mac TouchBar

  5. hello, when I put the script in, and run script. after which I save but when I look one touch bar it just says the name ‘script:spotify’

    any help?

  6. Is there anything I can do to limit the number of characters shown on that display? If a song name’s a bit longer than usual it takes up the entire touch bar.

      • It’s doable, replace line 7 of the script with:

        set artistTitle to ((get artist of current track) & " - " & (get name of current track))
        if length of artistTitle is less than 50 then
        	set displayTitle to artistTitle
        else
        	set displayTitle to text 1 thru 50 of artistTitle
        end if
        return displayTitle

        This displays the first 50 characters, you can adjust this arbitrary limit however you want (be sure to replace 50 in both lines!).

    • It’s doable, replace line 7 of the script with:

      set artistTitle to ((get artist of current track) & " - " & (get name of current track))
      if length of artistTitle is less than 50 then
      	set displayTitle to artistTitle
      else
      	set displayTitle to text 1 thru 50 of artistTitle
      end if
      return displayTitle

      This displays the first 50 characters, you can adjust this arbitrary limit however you want (be sure to replace 50 in both lines!).

  7. The widget worked normally for while, but now it stops displaying the song that is actually playing. It doesn’t display the current song anymore, and is stuck on this song that has been already played 3/4 hours ago. Any help? Thanks!

  8. Thanks a lot for this. One of those times where there is actually an application for the TouchBar and Spotify devs are not taking advantage,

  9. I’ve tried to merge iTunes and Spotify playing together:

    if application "iTunes" is running then
    	tell application "iTunes"
    		if player state is playing then
    			return (get artist of current track) & " - " & (get name of current track)
    		else if application "Spotify" is running then
    			tell application "Spotify"
    				if player state is playing then
    					return (get artist of current track) & " - " & (get name of current track)
    				else
    					return ""
    				end if
    			end tell
    		end if
    	end tell
    else
    	return ""
    end if
  10. Hello,
    That is what I’ve been looking for, thanks for the article.

    I have critical questiosn though. When I add widget with itues(or whichever), it starts displaying but It stops displaying after I press button “X” which is displayed before ESC. and after that I need to to save widget again to see current track.
    my touchbar have following buttons:
    (X) ESC itunes-playing track touchbar controls.

    Is there any way to get rid of (X) and always see currently playing track all the time regardless of application?

    I have widget in global settings

    • That’s the expected behavior: the “X” closes BTT’s custom TouchBar.
      I set a shortcut in the Keyboard section of the app that allows me to quickly open it back as needed.
      You have to look for the “Toggle BetterTouchTool Touch Bar” action, which I mapped to ^⇧T.

    • edit: think i figured it out, i added a couple extra spaces between the artist and song title, that seems to have done the trick!

      -- This script can be used in conjunction with Better Touch Tool to display the currently playing track on the MacBook Pro TouchBar
      -- More info here: https://lucatnt.com/2017/02/display-the-currently-playing-track-in-itunesspotify-on-the-touch-bar
       
      if application "iTunes" is running then
      	tell application "iTunes"
      		if player state is playing then
      			return (get artist of current track) & "   -   " & (get name of current track)
      		else
      			return ""
      		end if
      	end tell
      else
      	return ""
      end if
  11. Hello Luca!

    This is exactly what I was looking for but with one hitch, is it possible to also have the music controls with the name of the song/artist playing? This is so that you can see what is the next song when you skip etc… I tried making a custom script but to no avail. Any help would be appreciated! Thanks 🙂

    • You mean showing three buttons like these?
      (⏮ the song I played before this one) (⏯ this song) (⏭ the next song)

      I played around with AppleScript but I was unable to get the names of the previous and the next track in the currently playing playlist 😔

  12. Hi thank you so much for this,
    I know now it return a string with playing state,
    I’m trying to make a button that can copy the “return”(currently playing track string) into my clipboard,
    but didn’t work, is there a way can make it happen?

    • Hi,
      actually it’s pretty easy. You just have to assign the “Run AppleScript in Background” action to your custom Touch Bar button, and enter the same script you use for Spotify/iTunes, only replacing line 7 with this one:

      set the clipboard to ((get artist of current track) & " - " & (get name of current track))
    • You need to remove the first line of the script. When you add a new Widget and click the ‘Advanced Configuration’ button, BTT puts a default script (`return do shell script “date” #example: execute a shell script and use the result`) that returns the Date/Time. That script is just an example, and should be removed.

Leave a Reply

Your email address will not be published. Required fields are marked *