MacOS – Folder action acts on files not specified in the workflow

automatorfolder-actionmacos

I just started using Automator for the first time. My folder action gets two Finder items: say 'foobar1.pdf' and 'foobar2.pdf' files, and copies them to another folder.

It works but there is a side-effect: also the auxiliary files with the same name but different filename extensions (.aux .nav .snm .toc and .out) were also copied.

To solve that I created another folder action to send 'foobar1.aux', 'foobar1.nav' and so on to the Trash. But to test it, I did not add 'foobar2.aux', 'foobar2.nav' and so on. The new script works—the files are send to the Trash but now there is a beneficial side-affect: the auxilary files for 'foobar2' are also deleted even if they were not included in the workflow.

Is there a logical explanation for this behavior? Any way to avoid the side-effects?

copying files

cleaning the folder

Best Answer

A Folder Action workflow will give you every file when a change is detected in the specified folder, including ones you are not interested in.

Your problem is with Get Specified Finder Items. It just adds items to the list of files to process. It doesn't filter anything!

Use the Filter Finder Items action instead to filter the list returned by Finder. You can do it any number of fields/options including name, extension and type.

Filter Finder Items Action