Apple's just approved the latest update for Denied. Version 1.5.2 fixes a bug that prevented Denied from retrieving the 'disliked' state of a track when it did not have artwork.
You can get the update on the Mac App Store. 🚀
Instead of just pushing the update and forgetting the bug ever existed, I thought it would be interesting to tell you what exactly went wrong and how I resolved the issue.
Denied follows a set pattern to shape your listening experience.
- Get notified of a song change.
- Retrieve the song's properties.
- Check if these attributes match any rules.
- Skip the track if a match was found.
To fetch a song's title, artist etc. from iTunes or Spotify, Denied relies on AppleScript. This scripting language allows anyone to hook into an application (if it supports it) and retrieve information from it. Try this quick example.
- Launch Script Editor (/Applications/Utilities/Script Editor.app).
- Create a new document.
Copy-paste the lines below. (Make sure you copy the lines for the right player.)
Play a song.
Run the script.
You should see the name of the current track in the Description field of the Script Editor.
Besides the track title, Denied also fetches the artist, the album, the artwork and (for iTunes) whether a track is disliked. Here's what that script looks like.
This all works perfectly fine when scanning a track that has every property setup properly. The track's artwork isn't that reliable, unfortunately. Sometimes tracks don't have artwork at all, sometimes it takes a few moments before it's retrieved from the internet. I assumed the field would just remain empty then. That's not what happens, though.
If the song's artwork does not contain an image, the script returns the default value for all the parameters after it (
property isDisliked : false). You can see why this would prevent Denied from ever knowing if a song without artwork was actually disliked.
Instead of fetching the artwork in the same script as the other properties, I made a seperate method that handles everything artwork related. This is similar to how I implemented fetching artwork for Spotify.
This was a pretty easy fix and I'm happy Apple approved the update withing a few hours. I've added some songs without any artwork to my test suite, so this shouldn't happen again. I hope you found this interesting. 🙂