inconsistent folder actions

Troubles.

I currently have a very simple folder action script (below). ‘Hello’
does not always display. Sometimes it works, sometimes it doesn’t.

The original script sends an email ‘after receiving these_items’
and that too, suddenly, stopped working.

At this point, I’m dragging a file into the folder to test.
I get very inconsistent results.

Any tips?


on adding folder items to this_folder after receiving these_items
	repeat with an_item in these_items
		display dialog "hello!"
	end repeat
end adding folder items to

soda:

I have had a few problems in scripts that I have written using the syntax:

repeat with some_thing in every_thing

Sometimes those repeats work, but mostly they seem to be infuriatingly finicky.

I now almost always use this syntax:

repeat with some_thing from 1 to (count every_thing)

I hate using such bulky code, but I like things to work.

Hope this helps.

casdvm

It’s worth remembering that, in the ‘currentItem in someList’ form of repeat loop, the value of the variable ‘currentItem’ (or whatever) is initially a reference. In certain situations, it will be implicitly coerced to an appropriate class - but this is not always the case. If you ever need to explicitly evaluate it, use ‘contents of’. Compare, for example, these results:

set l to {}
repeat with n in {1, 2, 3}
    set l's end to n
end repeat
l
--> {item 1 of {1, 2, 3}, item 2 of {1, 2, 3}, item 3 of {1, 2, 3}}

set l to {}
repeat with n in {1, 2, 3}
    set l's end to n * 2
end repeat
l
--> {2, 4, 6}

set l to {}
repeat with n in {1, 2, 3}
    set l's end to n's contents (* or contents of n *)
end repeat
l
--> {1, 2, 3}