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
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}