Skip to content

Instantly share code, notes, and snippets.

@jkbockstael
Created October 25, 2017 12:43
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jkbockstael/597addd3f3f2965984f9c2805e18eb19 to your computer and use it in GitHub Desktop.
AppleScript to get iTunes to sort albums by release date
-- Fix albums display order
-- Changes the "sort album" field, to ensure that albums get displayed in chronological order on iPods.
-- CC-BY-NC 2011, Jean-Karim Bockstael,
tell application "iTunes"
-- input checking
if selection is {} then
display dialog "You must select at least a track"
return
else
set selected_tracks to selection
repeat with a_track in selected_tracks
if a_track's album = "" then
display dialog "All tracks must have their Album field filled"
return
end if
if a_track's year = "" then
display dialog "All tracks must have their Year field filled"
return
end if
end repeat
if length of selected_tracks > 1 then
set cur_album to album of item 1 of selected_tracks
set cur_year to year of item 1 of selected_tracks
repeat with a_track in selected_tracks
if a_track's album is not equal to cur_album then
display dialog "All tracks must share the same album name"
return
end if
if a_track's year is not equal to cur_year then
display dialog "All tracks must share the same release year"
return
end if
set cur_album to a_track's album
set cur_year to a_track's year
end repeat
end if
-- actual work
repeat with a_track in selected_tracks
set a_track's sort album to (a_track's year as string) & " " & (a_track's album as string)
end repeat
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment