Newbie Handler Question

This stripped down script works (doesn’t do anything, but it produces no errors):

set currentItem to “Kurt:kurt.tif” as file specification
dosomething(currentItem)

on dosomething(f)
end dosomething

But this one, which is the same thing except that it accepts files via drag & drop, errors
out:

on open fileList
tell application “Finder”
repeat with x from 1 to number of items in fileList
set currentItem to item x of fileList
dosomething(currentItem)
end repeat
end tell
end open

on dosomething(f)
end dosomething

Can anyone tell me why the second one will not call the “dosomething”
handler, failing with “Can’t continue dosomething”?

Thanks,
-Kurt

Model: iMac G5
AppleScript: 1.10
Browser: Safari 412
Operating System: Mac OS X (10.4)

Please search the forums and the FAQ:

http://macscripter.net/faq/get_the_faq.php?id=115_0_5_0_C

Jon

Can’t continue is a reply from AppleScript to a repeat statement with bad syntax. You say they are the same except for the droplet, but they are not the same. You changed something major. Who calls the handler in your script 1, and who calls the handler in script 2?

run this as a droplet, and you get the same result as script 1.


on open fileList
	
	repeat with x from 1 to number of items in fileList
		tell application "Finder"
			set currentItem to item x of fileList
		end tell
		dosomething(currentItem)--Now they are the same script
	end repeat
end open

on dosomething(f)
end dosomething


SC

You can also use “my” when calling one of your own handlers inside a tell block. Otherwise you’d have to split the blocks and (although not in this case) it could be anoying. Anyway, you can refer to “yourself” in several ways. For example, you can “tell me to quit” (but be carefull, this only works when the script has been saved as an app, and not when testing with AS).
Your same script (but with the smallest change) would now be:


on open FileList
	tell application "Finder"
		repeat with x from 1 to number of items in FileList
			set CurrentItem to item x of FileList
			my DoSomething(CurrentItem)
		end repeat
	end tell
end open

on DoSomething(f)
end DoSomething

Hope it helps.

Um, this is exactly what is covered in the FAQ link I posted above.

Jon

:smiley: … ups! Well… what Jon said then!

Do you really need to tell Finder something?