I have an Applescript that reports the currently playing song name, album, song number, and total number of songs on the album. If the album comes from a single CD or if the song comes from CD 1 of a multi-CD album, everything works, and I get the following:
Song 2 of 30
However, if the album comes from a multi-CD set, then the song number is incorrect for songs from CD 2, CD 3, etc. Here's an example: L'Elisir d'Amore has two CDs, and in iTunes, it is entered as such (e.g., CD 1 of 2 and CD 2 of 2). The script correctly reports there are 30 songs (16 on CD 1 and 14 on CD 2). When playing a song from CD 1, everything is accurate. When playing a song from CD 2, the song number begins again at 1, so the very last song appears as
Song 14 of 30
because it is the 14th song on CD 2. Is there a way to get the script to display Song 30 of 30 for the last song on CD 2 without some kludge of figuring out the number of CDs, then counting up the songs in CD 1 and then adding to the track number of the song in CD 2? This kludge gets quite ugly for albums spanning as many as 14 CDs.
Here's the simplified bit of code:
tell application "iTunes" -- code to check that there is a current song set z_album to album of current track as string set z_num to count of (every track whose album is z_album) set z_song to name of current track as string set z_trk to track number of current track log z_song & " (" & z_trk & " of " & z_num & ")" end tell