Having trouble with a simple folder action

Hello,

I’m still a bit of a novice with AppleScript and have been having some trouble getting what seems like a very simple folder action to work. I work in online interactive audio and want a simple automated process for converting newly exported hi-resolution audio files to the best low-bitrate setting available, which means using the LAME encoder via terminal with custom options.

Here’s my script that isn’t working:

on adding folder items to this_folder after receiving added_items
repeat with i from 1 to (count of added_items)
if name of (item i of added_items) does not contain “mp3” then
set audioName to name of (item i of added_items)
do shell script “cd ~/Desktop/LAME/”
do shell script "lame -a --abr 32 -B40 " & audioName & ".wav " & audioName & “.mp3”
end if
end repeat
display dialog “All .WAV files have been encoded to .MP3”
end adding folder items to

When I drop a file into the folder nothing happens. After digging around in various forums and tutorials, I suspect something having to do with my shell script commands or my conditionals to avoid the folder action from being triggered by the output of the encoder, creating an endless loop!

Any help would be much appreciated!

thanks,
Wally

Maybe this one will behave better.


on adding folder items to this_folder after receiving added_items
	tell application "Finder" -- <<<<<<<<<<<<<<<<<<
		repeat with i from 1 to (count of added_items)
			if name of (item i of added_items) does not contain "mp3" then
				set audioName to name of (item i of added_items)
				do shell script "cd ~/Desktop/LAME/"
				do shell script "lame -a --abr 32 -B40 " & audioName & ".wav " & audioName & ".mp3"
			end if
		end repeat
	end tell -- <<<<<<<<<<<<<<<<<<
	display dialog "All .WAV files have been encoded to .MP3"
end adding folder items to

Yvan KOENIG (VALLAURIS, France) lundi 16 janvier 2012 22:16:49

or this


on adding folder items to this_folder after receiving added_items
	set lameFolder to POSIX path of (path to desktop) & "LAME/"
	repeat with anItem in added_items
		set {name:fileName, name extension:fileExtension} to (info for anItem)
		if fileExtension is "wav" then
			set audioName to text 1 thru -5 of fileName
			do shell script "lame -a --abr 32 -B40 " & quoted form of (lameFolder & audioName & ".wav") & space & quoted form of (lameFolder & audioName & ".mp3")
		end if
	end repeat
	display dialog "All .WAV files have been encoded to .MP3"
end adding folder items to