basic question regarding folder action

Hi there,

with the kind help of some members of this forum I made a folder action script.

It should analyze the name of each file that is dropped into the folder, find a folder an the server based upon the name of the file and move it in that folder.

For the folder action I used this basic structure:

on adding folder items to this_folder after receiving these_items
repeat with i from 1 to number of items in these_items

end repeat
end adding folder items to

Now I’d like to ask:
What does the ‘repeat with i form 1…’ loop do? I copied it from another folder action but I don’t understand how it works (what is i) and if it is really necessary to process all the files that are dropped into the watched folder?

And a general question: Is there a way to log folder action to debug them?

Can anybody help me with that?


If you add another line the purpose becomes clear

on adding folder items to this_folder after receiving these_items
	repeat with i from 1 to number of items in these_items
		set currentItem to item i of these_items
		-- ...
	end repeat
end adding folder items to

When the action is called the parameter these_items contains a list of references to the added items.

The variable i is an index to be able to iterate the list of items. What you are going to do with the items is up to you

Regarding your supplementary question: You can use display dialog to display something or you could create a text file to log your stuff there.

You will only need a repeat loop if you are dragging more than one file (or folder) onto the hot folder at the same time. Otherwise, you only need 1 list item and you can do without the looping loop:

on adding folder items to this_folder after receiving these_items
	set droppedAlias to item 1 of these_items
	-- processing this alias
end adding folder items to

Well - thank you very much - very helpful.
I actually made (bastelte) the folder action script with the help from both of you.

As there will be several files dropped into the folder I will need the repeat loop, as I understand now.

The strange thing is, that the script stops working eventually when I drop too many files into the folder. Or maybe there is another reason I haven’t figured out yet.

Are there any general ideas on how to get a folder action more reliable or is this just depending on the actual script?


Improving the speed of the hot folder is a known issue. I personally never needed to drag and drop more than 1-5 files onto it to run into it. But as I read here and there, they offer 2 methods: 1) creating a custom workflow in the form of processing a queue 2) parallelizing a hot folder.

I would not use the first method, since the folder actions dispatcher is already a queue, and adding a new, custom queue to the hot folder script is a queue above the queue. I would have to study the whole theory of queues in order to avoid additional incidents. And I do not believe that this method is more effective than the next one. Since a sequential process never outperforms a parallel process

Second method. You create N hot folders inside a hot folder (and attach a separate script to each of them). For example, 26 hot folders by the number of letters of the English alphabet. The parent hot folder takes a bunch of files and immediately moves them to its nested hot folders by the initial letter of the file name. That is, distribution is the only purpose of the parent hot folder script. The final processing of the file is performed by the script of the corresponding subfolder. With N folders, the speed should be almost N times faster. This nesting process can be repeated deeper. Attach M other folders to each of N folders, the speed should increase by about N * M times

There will always be a limit, because the RAM is limited. But theoretically if your folder has successfully received 100 files before, now it will be able to receive up to 10010026 (260 000) files at the same time

thank you very much for the interesting insight.
I wouldn‘t have thought that this is such a fundamental problem for the framework.

Thank you as well for the 2 options to work around.