iTunes encoder - almost there

Hey all.

Got an iTunes problem. I’d like to be able to drop an mp3 on a script that would then convert the file to a particular bitrate of mp3, but not effect my regular standard bitrate that I leave in iTunes.

Here’s what I’ve got so far (there is also a folder that includes all the preferences for each individual bitrate).

on open audio_file
	--try
	--tell application "iTunes" to quit
	--end try
	
	set appPath to get path to current application as string
	set appFolder to replace_chars(appPath, "iTunes Bit Rate.app", "")
	set mp3PrefFolder to the result & "iTunes BitRates:"
	set homeFolder to get path to home folder as string
	set prefFile to homeFolder & "Library:Preferences:com.apple.iTunes.plist"
	set prefFolder to homeFolder & "Library:Preferences:"
	set tempFolder to mp3PrefFolder & "Original Preferences:"
	
	--display dialog prefFile & return & tempFolder
	tell application "Finder" to move file prefFile to tempFolder with replacing
	--display dialog "Made it"
	set newBitRate to GetNewBitRate()
	
	set bitFile to mp3PrefFolder & "Itunes " & newBitRate & ":com.apple.iTunes.plist"
	tell application "Finder" to duplicate file bitFile to prefFolder with replacing
	
	tell application "iTunes"
		activate
		
		set theAudioFile to add audio_file
		set convertedAudioFile to convert theAudioFile
		delete theAudioFile
		quit
	end tell
	
	
	set backPrefFile to tempFolder & "com.apple.iTunes.plist"
	tell application "Finder" to move file backPrefFile to prefFolder with replacing
end open



------------------------------------------------------------------------------------------------------------------------GET NEW BITRATE
on GetNewBitRate()
	set rateList to {16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320}
	
	set prefBitRate to choose from list rateList default items 1 with prompt "Select the MP3 Encoder Bit Rate you would like to use."
	
	
	return prefBitRate
end GetNewBitRate
------------------------------------------------------------------------------------------------------------------------GET NEW BITRATE

------------------------------------------------------------------------------------------------------------------------Replace Characters
on replace_chars(this_text, search_string, replacement_string)
	set AppleScript's text item delimiters to the search_string
	set the item_list to every text item of this_text
	set AppleScript's text item delimiters to the replacement_string
	set this_text to the item_list as string
	set AppleScript's text item delimiters to ""
	--display dialog "Made it to sub"
	return this_text
end replace_chars
------------------------------------------------------------------------------------------------------------------------Replace Characters

All works fine now. However, if you attempt to run the script a second time, it says the operation cannot be completed. But if you relaunch the Finder, then it will work again. Any ideas?

Thanks

anyone ever had an instance where the Finder had to be relaunched in order to run a script a second time? This should be an easy fix, but I have no experience with this issue.

Thanks