Processing specific files not working

Hi, I am basing this code off another post I received help with but cannot figure out why it is not working.

It seems like the if statement is not catching any files.



on adding folder items to thisFolder after receiving addedItems
	
	repeat with anItem in addedItems
		
		if (name extension of anItem contains "avi") or (name extension of anItem contains "mkv") or (name extension of anItem contains "mp4") then
			tell application "iFlicks"
				import anItem with gui
			end tell
		end if
		
	end repeat	
	
end adding folder items to


If I get rid of the if / then statement then the script works great but tries to process every file.

Any idea?

Thanks.

Phil

Hi,

you’ve got to tell the finder to get name extension.
Using folderactions it’s good to use errorhandling to get some response if it doesn’t work as expected …

on adding folder items to thisFolder after receiving addedItems
	
	repeat with anItem in addedItems
		try
			tell application "Finder" to set theSuffix to name extension of anItem
			if theSuffix is in {"pdf", "jpg"} then
				tell application "Preview"
					open anItem
				end tell
			end if
		on error e
			display dialog e
		end try
	end repeat
	
end adding folder items to

Thanks Hans.

I modified your code to this and I still get nothing. No errors and no processing if I put an avi or mkv file in the folder.


repeat with anItem in addedItems
	try
		tell application "Finder" to set theSuffix to name extension of anItem
		if theSuffix is in {"avi", "mkv"} then
			tell application "iFlicks"
				import anItem with gui
			end tell
		end if
	on error e
		display dialog e
	end try
end repeat

end adding folder items to



Any ideas?

Thanks

Phil

I tried to put a display notification in too to display theSuffix but it doesn’t do anything.


repeat with anItem in addedItems
	try
		tell application "Finder" to set theSuffix to name extension of anItem
		display dialog theSuffix
		if theSuffix is in {"avi", "mkv"} then
			tell application "iFlicks"
				import anItem with gui
			end tell
		end if
	on error e
		display dialog e
	end try
end repeat

end adding folder items to

Hi,

in your modified script the first line is missing …

on adding folder items to thisFolder after receiving addedItems

This works perfect thanks.

Any idea how I can make the script look in sub folders too?

Cheers.

Phil