listenbrainz-scrobbler

3 min read Original article ↗

ListenBrainz macOS Scrobbler for Music.app

⚠️ Fixed for macOS Tahoe 26.1

After the issue with Tahoe 26 and 26.0.1, Apple started fixing the Apple Script. The main issue that remains is that the track number is not recognized, so the MetaBrainz guess could be wrong. Anyway, in a few tests I did it worked well.

More precisely, for local songs on the Mac the script works fine. But all the tracks streamed from Apple Music have track number set to 0.


Since I wouldn't know where to start to write a proper macOS app, I wrote a Bash script which:

  • Gets information of the playing track on Apple Music.app, every 30 seconds
  • Queries MusicBrainz with the title, track and the album got from Music.app
    • The API response is parsed to get the first recording witht the matching track number
    • That recording's MBIDs will be submitted
  • Submits the listen to ListenBrainz with the current time
  • If the Music.app is not open, does nothing (waits 30 seconds)
  • If nothing is playing, does nothig (still waits 30 seconds)

I tested only with tracks from Apple Music subscription also with songs from my library (old CD rips from iTunes), and it seems to work.)

It's very quite rough, but it works.

Requirements

The only requirement is jq, which can be easily installed with Brew.

Instructions

  • Copy the file scrobbler.sh in a directory, e.g. your home ~/
  • Give it appropriate permissions: chmod +x ~/scrobbler.sh
  • Get your ListenBrainz token here
  • Set the token as the variable in the second line of the script: TOKEN="aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeeeeee"
  • From the terminal, just run ~/scrobbler.sh

You will see a (quite useless) notification:

Then you can just search and play tracks from Music.app! 🎵

To stop the script, just press CTRL-C. A "Scrobbling stopped" notification will appear.

Wrap it with Automator

I recommend to let the script run in a terminal window, but you can create an actual application by wrapping the script with Automator (I found the instructions here).

  • Open Automator.App
  • Choose "New Document"
  • Select "Application"
  • In the top-left search box, search "Run Shell Script" and double-click it
  • On the right frame, choose /bin/bash from the menu
  • Below, paste the whole scrobbler.sh content except for the first #!/bin/bash line (remeber to set $TOKEN)
  • You can test the script with the "Run" button in the top-right corner
  • Save your Application file where you want (/Applications is fine)
  • Run it!

While the application runs, you'll see a gear spinning in the menu bar. To stop the app, click on the gear and then on the right button, ash shown below:

Improvements and TO-DOs

The biggest concern about the recording lookup. Since ListenBrainz's API has some limitations, I switched the query towards MusicBrainz's one.

When I get the album and track name from Music.app, I strip off some substrings (e.g. Single, EP, Unreleased) because they messed up the search results with the tests I made.

I'm aware that's not perfect, but the issues I encountered arised only with songs from my library, with weird titles (e.g. "Home Again To You [Bonus Track - Previously Unreleased]"). There should be no issue with songs streamed by Apple Music.

Feel free to contact me, or open an issue!