iTunes Folder Sync

You can manipulate iTunes on Windows with Javascript! This was a shock & a relief to me, on Mac OS they have Apple Script but I thought we were SOL on Windows. Anyway this has helped me fix one of the most vexing problems with iTunes: It can’t find new music on your hard drive automatically.

The Problem: iTunes Music Library isn’t as super fly as Winamp’s just yet. With Winamp you can store your music in any way you like, say: full albums in their own folder, singles in their own folders separated by genre. Winamp scans these folders (as many as you want) on startup looking for anything new. New music is automatically added to the Winamp library, not so with iTunes. You have to go in and re-import each folder. So I was looking for a way to make iTunes do this automagically.

The Solution: iTunesFolderSync.js

The script performs the following tasks:

  • Scans all your library and remove any tracks that iTunes cannot find on your hard drive.
  • Collect a list of all the folders you store music in.
  • Import all those folders back into iTunes, catching all the new stuff in the process.
  • Initiate a sync with your iPod if one is attached.
  • Lets you know how many tracks were added and removed from the library.

Folder Sync is great for getting new stuff into iTunes that you have just downloaded, like podcasts. Its also great when you are organising your music, moving/renaming files and you want to sync up the library. You can have the script run after downloading podcasts using iPodder.

Technical Notes:

  • You need the Windows Scripting Host and the .js extension set to be executed using \windows\system32\wscript.exe
  • If you have music in formats that iTunes cannot read you will be asked to convert those tracks, even if they already exist in the library. The best thing to do here is to convert the tracks once and replace the originals with the conversions. This way you won’t get asked twice. You could also by lazy and just press ‘skip’.
  • The iTunes SDK is here for you more intrepid hackers. You don’t need the SDK to run the script though.



4 Responses to “iTunes Folder Sync”

  1. Gravatar of dedi dedi
    2. June 2005 at 10:03

    does this retain all the metadata like Ratings and Last Played?

  2. Gravatar of Administrator Administrator
    2. June 2005 at 10:24

    The short answer is yes, your metadata is safe.

    Any new songs that it imports will have an import data/time of when the script was run. iTunes will notice when you attempt to import a duplicate song and skip the import so all exisiting tracks are safe. Information for missing songs is of course deleted.

    Generally my missing tracks are podcasts I deleted or tracks that I changed the file names for. If you rename or move lots of things with something like MP3 Tag&Rename, for instance, this script can save lots of time. Meta data for renamed songs will be lost though. If you want to keep the metadata in that case you must use iTunes to rename the song.

    I’m going to add a warning that people with music stored on removable drives. They should either avoid this script or always run the script with the removable drive connected. If the drive was not connected all the music on that drive would be removed from the library.

  3. Gravatar of howie howie
    30. September 2005 at 05:08

    For me the script is deleting dead stuff OK, but it does not import newly added songs. In fact, not sure how it knows where to look for the new stuff. I tried setting the iTunes music folder to the root of where I store all the music, but it still didn’t get the new stuff.

    Am I missing something?

    Would be great if I could get this to work, as I am tired of continually clearing and re-importing the library!!!



  4. Gravatar of Matt Chan Matt Chan
    29. March 2007 at 09:31

    Nice Script!


    You need to open up the JavaScript in Notepad. You can add directories in there.