Categories
Hacks Mac

Applescript: Number Selected Tracks Sequentially

I think you can tell from the title what this simple applescript does. I’m sure this code could be made much shorter, but I’m really a novice, and this works pretty well, albeit there are no foolproofs.  

Here’s what it does: You select some songs that are already in order (how? see below), say 12 songs that you already arranged. You then run the script… it numbers them 1 of 12, 2 of 12, 3 of 12… and so on up to 12 of 12. You now have a nicely organized album.Album not in order?

Instructions: Select all the album tracks. Make a new playlist from selection (cmd+shift+N). Click the title bar above the first column, in other words: sort by number in playlist. Then, you can rearrange the songs as you like. Now select all the songs, and finally run the script.Ahh, finally some home-brewed automation for sorting out this messy iTunes library. 

--Number Selected Tracks Sequentially
--A simple applescript from Rex Pechler
--http://rex.fm
--
--2007

tell application "iTunes"
if selection is not {} then
set sel to selection
set these_files to {}
set numtracks to the count of sel
set trackcount to 0
with timeout of 30000 seconds
repeat with this_track in sel
if class of this_track is file track then
set trackcount to trackcount + 1
set the track number of this_track to trackcount
set the track count of this_track to numtracks
end if
end repeat
end timeout
else
set count to 0
end if
end tell

Download: the applescript as text or as a binary app.

Leave a Reply

Your email address will not be published. Required fields are marked *