This is a question from Wil Wheaton's google+, but I would like to get an answer too, stackexchange style.

Suppose you have all your music in a folder called /iTunes/Music. When you add files to iTunes, it puts them inside this folder, so it looks like this: /iTunes/Music/artist/album/track

Suppose you recently eliminated about 10GB of music from your iTunes library, but stupidly left those files inside /iTunes/Music. You have the entire thing backed up and pristine on an external drive, so you don't need to keep that music in that folder.

Here's the question: you want to write a script that will compare your iTunes library to the contents of /iTunes/Music, identify files that are in /iTunes/Music but not the iTunes Library file, and move them to a new folder (probably in /tmp) so you can take a look, then delete them.

One possible solution would be to write a script which puts the output of ls (with appropriate flags) into a file, then diff that file with the contents of Library.xml, and move the resulting files into a new directory. Is it possible to do this?

Maybe there is already an Applescript which can be used to achieve this?

2 Answers 2


You could move the location of your iTunes Media folder, which will only move those files actually in the iTunes library.

It may take a while, even if the source and destination are both on the same drive (it's still got to tell the OS to move each file individually), but should leave behind any files that aren't in the library.

The iTunes Media folder location is set in iTunes Preferences, under the Advanced tab. This will of course only work if you have "Keep iTunes Media folder organized" checked (which judging by your question is the case).

I would suggest something as simple as changing just the name of the folder it's currently set to (i.e. keep it somewhere in your home folder, or whatever drive it's currently on), and then move it back after you've cleaned out the 'orphaned' files.

  • 1
    After you change the folder you'll need to run Organize Library with the Consolidate Files option checked. Full instructions are here: support.apple.com/en-us/HT201562
    – Nate
    Commented Dec 4, 2014 at 8:31

Try this script. It's from Doug's AppleScripts. I never used it, but sounds like what you are looking for.

  • Whilst your answer may theoretically answer the question, it would be preferable to include the essential parts of the article in an answer below, and provide the link for reference
    – Pfitz
    Commented Dec 5, 2012 at 7:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .