# How to prevent iTunes from adding converted Mp3s to the library?

When I use iTunes to create Mp3 files from songs I've bought, iTunes also adds them to my library and I got them twice. How can I prevent iTunes from adding converted Mp3s to the library in the first place?

EDIT:
I'm using iTunes on Mac OS X

EDIT2:
Chris Johnsen's answer is quite good and worth the bounty. However, I also tried this script Chris pointed me to, and that's even better and I'll use this from now on. Thanks folks.

-
I've never noticed it do that - is it new with 9? – warren Sep 28 '09 at 10:07
@warren: No, that isn't new – Tim Büthe Sep 28 '09 at 14:34

If you are OK with temporarily having the converted tracks in your iTunes library, you could use AppleScript to convert the track, remove the reference to the converted track, and finally move the converted file where ever you like.

Plain AppleScript has little capability for smooth UI, but the following script might do what you want. Paste it into Script Editor (or AppleScript Editor on Snowy) and save it as an “application bundle” (“application” on Snowy). To use it, configured your conversion settings (Import Settings) in iTunes, select some tracks in iTunes, then drop a folder on the saved application. Note that newly converted files will overwrite pre-existing files in the dropped folder (if their names are identical). It is probably best to drop empty folders unless you are sure you want any overwrites you might get. You might even get some ID3v2 tags out of the process (I did in some testing, but it depends on what iTunes decides to do).

on run
display dialog "Drop a folder on this application to convert iTune's selected tracks and place them the dropped folder." & return & return & "The converted files will be whatever is selected in iTunes “Import Settings”." with title "About"
return

-- Test invocation:
"/tmp/convert_to_external"
alias POSIX file result
open {result}
end run
on open theItems
if length of theItems is 0 then
display dialog "No items dropped? Only a single, plain folder should be dropped." with title "Error: Drop Only a Single Folder"
return
end if
if length of theItems is greater than 1 then
display dialog "Too many items have been dropped. Only a single, plain folder should be dropped." with title "Error: Drop Only a Single Folder"
return
end if
set theItem to first item of theItems
set info to info for theItem
if not folder of info or package folder of info then
display dialog "“" & POSIX path of theItem & "” is not a plain folder. Only a single, plain folder should be dropped." with title "Error: Drop Only a Single Folder"
return
else
|convert iTunes selection into folder|(theItem)
end if
end open
to |convert iTunes selection into folder|(folderRef)
try
do shell script "test -d " & quoted form of POSIX path of folderRef
on error m
display dialog "Destination (" & destinationForShell & ") not accessible?" & return & m
return
end try

tell application "iTunes"
set trackList to selection
repeat with selectedTrack in trackList
try
set convertedTrack to my convertTrack(selectedTrack)
set convertedFile to location of convertedTrack
my deleteTrackReference(convertedTrack) -- only delete the iTunes ref, not the track's file
my moveItemToFolder(convertedFile, folderRef)
on error m
tell me to display dialog m with title "Error During Conversion/Removal/Move" -- giving up after 30
end try
end repeat
end tell
end |convert iTunes selection into folder|
to convertTrack(aTrack)
if class of aTrack is list then error "Must pass a single track."
using terms from application "iTunes"
set questionTimeout to 10
set conversionTimeout to 600
display dialog "About to start conversion of “" & name of aTrack & "”. Select a timeout in seconds for the conversion (conversion will auto-start in " & questionTimeout & " seconds):" default answer conversionTimeout with title "Conversion Time Limit" giving up after questionTimeout
try
set conversionTimeout to (text returned of result) as number
end try

set convertedTrack to missing value
with timeout of conversionTimeout seconds -- conversion may take longer than the deafult 120 second AppleEvent RPC timeout
try
set convertedTrack to convert aTrack
on error
error "Error while converting track."
end try
end timeout
if convertedTrack is not missing value then return first item of convertedTrack
error "Abandoning track conversion after timeout." & return & m
end using terms from
end convertTrack
to deleteTrackReference(aTrack)
try
tell application "iTunes" to set mainLibrary to ¬
first library playlist of (first source whose kind is library)
on error
error "Unable to find main library playlist object."
end try
using terms from application "iTunes"
try
set convertedTrackInMainLibrary to ¬
(first track of mainLibrary whose database ID is (get database ID of aTrack))
on error
error "Unable to find track object in main library playlist."
end try
try
delete convertedTrackInMainLibrary -- deletes the reference, not the actual file
on error
error "Unable to delete track from main library playlist."
end try
end using terms from
end deleteTrackReference
to moveItemToFolder(itemRef, folderRef)
set itemPath to POSIX path of itemRef
set folderPath to POSIX path of folderRef
try
do shell script "mv " & quoted form of itemPath & " " & quoted form of folderPath
on error m
error "Unable to move item (" & itemPath & ") to destination (" & folderPath & "):" & return & m
end try
end moveItemToFolder

-
Sounds promising, I'll definitely will give this a try. Have you wrote that by yourself? Are your sure it doesn't drop my whole library...? – Tim Büthe Oct 22 '09 at 8:59
Yes, I wrote it in response to your question here. It should not hurt your library. And anyway, you already make regular backups like any good "super" user, right? The only tracks it ever removed from my library were the new, converted ones. The only potentially dangerous commands are the delete to remove the new, converted track and the mv to move the file of the converted track. Even if it did some how remove the wrong track, it would put the audio file in your output dir, so you would not lose it (though it would have been removed from any playlists). – Chris Johnsen Oct 22 '09 at 12:14
Also, if you don't like/trust my script, check out Doug's AppleScripts for iTunes (dougscripts.com/itunes). Convert and Export (dougscripts.com/itunes/scripts/ss.php?sp=convertandexport) and Drop A Few My Way (dougscripts.com/itunes/scripts/ss.php?sp=dropafewmyway) are similar to my script but include a bit more functionality. – Chris Johnsen Oct 23 '09 at 1:34
Thanks a lot Chris. The Script works and I'll accept your answer. However, for every Track pops up a dialog, asking for the "Conversion timeout...". How can I get rid of that? – Tim Büthe Oct 23 '09 at 6:52
I'm glad I was able to help you out. To get rid of the per-track dialog: delete (or comment-out) the four lines “display dialog "About to start conversion…/try/set conversionTimeout to …/end try”. (* AppleScript block comments (multi-line) start with open-paren+asterisk and end with asterisk+close-paren *) -- AppleScript end-of-line comments start with hyphen+hyphen – Chris Johnsen Oct 23 '09 at 8:55

As far as I know, there is no way to do this. You might want to use a different app, like Quicktime or AudialHub to do the conversion instead. Do you want to keep the original, or the new file in iTunes? You can create smart playlists to help you collect either one into a single list to remove them all from your library in one step (opt-delete in OS X).

-
Yes, I want to keep the originals. I just want to create the mp3s, to put them an another device and delete them afterwards. – Tim Büthe Sep 28 '09 at 14:35
i think this is the best scenario, unless there's an iTunes configuration option we're missing. if you go this route make sure the encoder app puts the output in a special directory (eg not in the iTunes library tree, or under any folder you've told iTunes to watch). – quack quixote Oct 18 '09 at 5:38

Move the created MP3 files to another directory outside of the tree that iTunes will scan for new content.

I assume that you use something other than MP3 as your primary audio format, so create a batch job to move any MP3 content from your iTunes directory tree into a separate location.

For instance, use ROBOCOPY.EXE to do this:

c:\windows\robocopy c:\itunes-path c:\mp3-files *.mp3 /s /zb /mov /xo


This command will move MP3 files in all subdirectories except if the target already exists and the source is older. You can add /mot:5 to the end in order to have it repeat itself every 5 minutes.

-
I'm on Mac OS and that won't work for me. Also, that leaves the songs in your library, with an exclamation mark next to it, because the file could not be found. – Tim Büthe Oct 17 '09 at 10:05

Depending on how often you do this, you could export a playlist to an MP3 Disc. You'll need to burn a disc each time but a rewriteable might solve that issue.

Steps:

1) Create a playlist of the songs you want

2) Right click on the playlist and choose "Burn playlist to Disc"

3) In options that come up, choose MP3 CD and click burn.

4) The songs will be burned to the disc in MP3 format.

5) Grab the songs from the disc when it mounts in the finder do with them what you will.

It does involve a somewhat tedious step of burning the CD but it doesn't require anything third party and is a function within iTunes.

-
A virtual drive would be possible... I may try this. – Tim Büthe Oct 19 '09 at 7:00

Edit: I suggested some general solutions, but it seems iTunes doesn't have the necessary features for any of them, so I've removed the suggestions.

-
First, iTunes does not add files to the library automatically. Secondly, I think you can't define an output folder, can you? – Tim Büthe Oct 19 '09 at 7:03