Automatically Number Songs in iTunes
Hello All,
iTunes currently has no built-in function to automatically edit the track numbers of multiple songs. If you use a Mac, there is an AppleScript called "Albumize Selection" that accomplishes this task, but after many, many hours spent searching the internet, I was unable to find a solution for Windows. With my limited programming knowledge, I was able to write a simple script that will accomplish this task, and I thought I would share it with everyone.
This script (JavaScript) runs on the built-in Windows Script Host - it does not require any third party software. The script will assign consecutive track numbers to the songs selected in iTunes, and will also update the total track count. For example, if you select 20 songs in iTunes, and run the script, it will number them 1 of 20, 2 of 20, 3 of 20, etc. I am running Windows 7, but it should work on any modern version of Windows.
To Save the Script:
1. Copy and paste the script into NotePad.
2. Save the file as MyFile.js ***It is very important that you type the extension .js, because this tells Windows that the file is a script!***.
To Use the Script:
1. Select the songs in iTunes (Click the first song, and then Shift-Click the last song).
2. Double-Click the JavaScript file in Windows Explorer.
The Script:
try
{
var Tracks = WScript.CreateObject("iTunes.Application").SelectedTracks;
var i = 0;
var j = Tracks.Count;
var CurrentTrack;
while (i != j)
{
i++;
CurrentTrack = Tracks.Item(i);
if (CurrentTrack.Kind == 1)
{
CurrentTrack.TrackNumber = i;
CurrentTrack.TrackCount = j;
}
}
}
catch(err)
{
WScript.Echo("The script could not be executed. No tracks were selected.");
}
WScript.CreateObject("WScript.Shell").AppActivate("iTunes");
WScript.Quit();
Tips:
1. You can save the script anywhere on your computer; I keep mine in the iTunes folder.
2. You can create a Windows shortcut to the script. This allows you to set the shortcut's icon, and allows you to assign a keyboard shortcut (such as Ctrl-Alt-N).
3. You can use iTunes while the script is running.
I hope people found this helpful! Let me know if you have any questions!
- David
iTunes for Windows-OTHER, Windows 7, Windows Script for iTunes