Applescript to find albums missing songs
projects This was the first AppleScript I ever made. In the past, I've had problems with iTunes randomly deleting a song or two from various albums. As a result, I needed something that would run through my library and tell me which albums have missing songs. This script does that, adding the albums to a playlist called "Missing". It's not the best written script, as it was my first, and has a bunch of quirks, such that your library needs to be tagged properly with exact track and disc counts. Also, there's a section of code for checking albums with multiple discs that is poorly written and only works with the library does not have an album with more than 6 discs. Either way, here's something to enjoy.
tell application "iTunes"
--Part 1: Get list of every album in the library
set albumList to {}
set musicLibrary to (get view of front browser window)
set musicLibraryName to (get name of musicLibrary)
set trackCount to count of every track of musicLibrary
set processedCount to 1
set new_playlist to make new playlist with properties {name:"Missing"}
repeat while processedCount ≤ trackCount
set theAlbum to album of track processedCount of musicLibrary as string
set add2List to true
if albumList contains theAlbum then set add2List to false
if add2List is true then
set albumList to albumList & (theAlbum as string)
end if
set processedCount to processedCount + 1
end repeat
set playlistCount to 0
repeat with theAlbum in albumList
-- gather album tracks
set these_tracks to (file tracks of musicLibrary whose album is theAlbum)
set num_these_tracks to count of these_tracks
set something to (track 1 of musicLibrary whose track number is 1 and album is theAlbum)
set discvariable to 0
if disc count of something is 1 then
set discvariable to track count of something
end if
if disc count of something is 2 then
set something1 to (track 1 of musicLibrary whose disc number is 1 and album is theAlbum)
set something2 to (track 1 of musicLibrary whose disc number is 2 and album is theAlbum)
set discvariable to ((track count of something1) + (track count of something2))
end if
if disc count of something is 3 then
set something1 to (track 1 of musicLibrary whose disc number is 1 and album is theAlbum)
set something2 to (track 1 of musicLibrary whose disc number is 2 and album is theAlbum)
set something3 to (track 1 of musicLibrary whose disc number is 3 and album is theAlbum)
set discvariable to ((track count of something1) + (track count of something2) + (track count of something3))
end if
if disc count of something is 4 then
set something1 to (track 1 of musicLibrary whose disc number is 1 and album is theAlbum)
set something2 to (track 1 of musicLibrary whose disc number is 2 and album is theAlbum)
set something3 to (track 1 of musicLibrary whose disc number is 3 and album is theAlbum)
set something4 to (track 1 of musicLibrary whose disc number is 4 and album is theAlbum)
set discvariable to ((track count of something1) + (track count of something2) + (track count of something3) + (track count of something4))
end if
if disc count of something is 5 then
set something1 to (track 1 of musicLibrary whose disc number is 1 and album is theAlbum)
set something2 to (track 1 of musicLibrary whose disc number is 2 and album is theAlbum)
set something3 to (track 1 of musicLibrary whose disc number is 3 and album is theAlbum)
set something4 to (track 1 of musicLibrary whose disc number is 4 and album is theAlbum)
set something5 to (track 1 of musicLibrary whose disc number is 5 and album is theAlbum)
set discvariable to ((track count of something1) + (track count of something2) + (track count of something3) + (track count of something4) + (track count of something5))
end if
if disc count of something is 6 then
set something1 to (track 1 of musicLibrary whose disc number is 1 and album is theAlbum)
set something2 to (track 1 of musicLibrary whose disc number is 2 and album is theAlbum)
set something3 to (track 1 of musicLibrary whose disc number is 3 and album is theAlbum)
set something4 to (track 1 of musicLibrary whose disc number is 4 and album is theAlbum)
set something5 to (track 1 of musicLibrary whose disc number is 5 and album is theAlbum)
set something6 to (track 1 of musicLibrary whose disc number is 6 and album is theAlbum)
set discvariable to ((track count of something1) + (track count of something2) + (track count of something3) + (track count of something4) + (track count of something5) + (track count of something6))
end if
-- if disc count of something is 1 then
if num_these_tracks is not equal to discvariable then
-- find highest track number
set hi_track_count to 0
repeat with a_track in these_tracks
set tk_num to track number of a_track
if tk_num > hi_track_count then set hi_track_count to tk_num
end repeat
repeat with j from 1 to num_these_tracks
set a_track to item j of these_tracks
if track number of a_track is 0 then
duplicate a_track to new_playlist
end if
end repeat
repeat with i from 1 to hi_track_count -- for each number thru hi_track_count...
repeat with j from 1 to num_these_tracks -- check each track
set a_track to item j of these_tracks
if track number of a_track is i then
duplicate a_track to new_playlist
end if
end repeat
end repeat
end if
--end if
end repeat
display dialog "Finished making album playlists!" buttons {"OK"} default button 1 with icon note
end tell
Applescript,
Programming,
iTunes 