Folder Actions AppleScript for iTunes - Add MP3 from downloads

I am trying create an applescript that will automatically add only downloaded MP3’s from my download folder as a Folder Action. I found the following script online and it works great except for two things: iTunes launches anytime I download anything from the Internet and also adds pretty much any file that iTunes is willing to add from that download folder. I’ve tried modifying the code about 15 different times and every time either iTunes does not launch, or iTunes launches for any file downloaded and does not add the file

The original code I started working with is:


on adding folder items to my_folder after receiving the_files
    repeat with i from 1 to number of items in the_files
        tell application "iTunes"
            launch
            try
                set this_file to (item i of the_files)

                add this_file

            end try
        end tell
    end repeat
end adding folder items to

Thanks in advance.

Hi. I don’t believe it should be necessary to launch the app inside the loop like that, but I don’t have the time to test it. Perhaps something along these lines may work:

on adding folder items to my_folder after receiving the_files
	tell application "Finder" to repeat with fileTarget in the_files
		if fileTarget's kind is "MP3 audio" then move fileTarget to ((path to music folder as text) & "iTunes:iTunes Media:Automatically Add to iTunes.localized")
	end repeat
end adding folder items to