Find tracks not in any Playlist in Apple Music (iTunes)

Jenia Varavva
2 min readApr 2, 2022

I use Apple Music (fka iTunes) to organize my DJ library. After I download a track I want in my library, I add it to Music and assign it to one or more genre playlists. I then use these playlists to manage my music in Rekordbox.

I started noticing that the playlist assignment sometimes gets lost, i.e. I add a track to my library into a playlist, then come back sometime later and the track is no longer in the playlist, however, it’s still in e.g. Recently Added.

That’s a mystery that I wasn’t able to resolve, but what I now do instead is go back to the collections every now and then and pick all the orphaned tracks that ended up in no playlists.

There’s no straightforward out-of-the-box way to find these orphaned tracks, so I’ve put together a MacOS Javascript script to shuffle some data from the Music app and print the list of tracks that ended up unsorted.

Open theScript Editor app, switch the bottom panel to “Messages” and run:

(() => {
const hasPlaylists = (tr) => {
if (tr.playlist.length === 0) {
return false;
}
if (tr.playlists.length === 1 && tr.playlists[0].name() === "Recently Added") {
return false;
}
return true
}

const app = new Application("Music");
let musicPlaylist = null;
const tracksWithoutPlaylist = [];
for (let i = 0; i < app.playlists.length; i++) {
const pl = app.playlists[i]
// "Music" playlist contains all the songs.
if (pl.name() !== "Music") continue;

musicPlaylist = pl;

for (let t = 0; t < pl.tracks.length; t++) {
const tr = pl.tracks[t];

if (!hasPlaylists(tr)) {
tracksWithoutPlaylist.push(tr);
}
}
}

console.log(`Total tracks ${musicPlaylist.tracks.length}, orphaned ${tracksWithoutPlaylist.length}`)

tracksWithoutPlaylist.sort(
(a, b) => a.artist() < b.artist() ? -1 : 1
).map(t => {
console.log(`${t.artist()} - ${t.name()}`)
});
})()

--

--