The Pug Automatic

Set ID3 track numbers from filename prefixes in iTunes

Written January 14, 2007. Tagged OS X, AppleScript.

I wrote an AppleScript (download) for iTunes to set ID3 (metadata) track numbers from number prefixes (ignoring leading zeros) in the filenames. So for filenames like 01. Foo.mp3, 2-Bar.mp3, 003_Baz.mp3, 4 Balloon.mp3 and 5Frou.mp3, the track numbers will be set to 1, 2, 3, 4 and 5 respectively.

For some reason, many MP3 songs I come across will be well-tagged except for the track number, though present in the filename.

I still miss ID3-TagIT (version 2, not 3) from my Windows days, but I think I'll get by pretty well with this script, Track Parser and File Renamer.

Put the script in ~/Library/iTunes/Scripts, creating the directory if it doesn't exist. A script menu (looking like a stylized scroll) should appear in iTunes. Select a couple of songs and choose the script from the menu to apply it.

I started out with Filenames to Song Names by Doug Adams. Instead of sticking the filename into the song name field, I pipe it through a Ruby one-liner and stick the result into the track number field.