Script: iTunes/Renumber Selected Tracks to Current Order

This is the third in a series of posts about the scripts I use with FastScripts.

  • Script: Renumber Selected Tracks to Current Order
  • Application: iTunes
  • Suggested key binding: None

Peek:

tracks      = Appscript.app("iTunes").selection.get
track_count = tracks.length

tracks.each_with_index do |track, ix|
  track.track_number.set ix + 1
  track.track_count.set track_count if track_count > track.track_count.get
end

This script acts on the the selected tracks in iTunes, setting their track number metadata according to their current sort order.

It’s great to quickly fix albums that come with less-than-stellar metadata (and you’d not be surprised at all by how many independent labels selling digital downloads botch this up).

This will also set the track count (the y in “track x of y”) to the number of tracks currently selected, except when this value is already set to a greater value.

This last trait makes this script also useful to simply set the track count info, and this is paid even less attention to by content providers. It’s sadly common to get an album with proper track numbers, but without the track count info.

Get the standalone script file, or git pull if you’re keeping a git clone of the scripts.

Got comments? Use reddit and/or poke me on twitter.