Has anyone successfully created an Automator script that works sensibly without errors?

I like to keep my files very organized, so I used Automator to organize files in my Downloads folder automatically based on the type of file. I created a very simple workflow that watches the Downloads folder for any file additions, and simply move them to the appropriate folder (Documents, Images, Videos, Music).


Initially, i just used the "kind" parameter to move the files. For example, if kind is music, move to Music folder, etc. But Automator was frequently moving the files to the wrong folder (music files could be moved to any folder like images, videos, or even documents). I suspected macOS to be unable to differentiate the file formats due to lack of native support, so i edited the workflows to now look for specific file extensions, and move the files accordingly. A sample workflow is here:


As you can see above, the workflow is as simple as it can be. Yet, I found that music files would be moved to other folders. I tried copying the same file several times to the downloads folder, and surprisingly, Automator would move the same file to different folder each time. This was ridiculous because Automator worked without any sense.


It is a bug with Automator as of now. I tried looking for alternatives, and there is only one app that i found - Hazel.


But it is incompatible with Catalina as of now. Read here.


Does anyone know of an alternative? Or has anyone successfully created (and wouldn't mind sharing the workflow) an Automator script that works sensibly without errors?


Thanks.


[Re-Titled by Moderator]


MacBook Pro 13", 10.15

Posted on Oct 21, 2019 11:13 PM

Reply

Similar questions

17 replies

Oct 24, 2019 3:10 AM in response to Sridhar Ananthanarayanan

Finding files relies on Spotlight, regardless of the criteria (file name, kind, size, date, or whatnot), so it could well be Spotlight.


If I understand correctly, you have several folder actions associated to your Downloads folder - one for each type of files (Music, Photos, etc).


The fact that the file was moved incorrectly is more likely to be caused by a false positive in the Find Finder Items than by the Move Items mistaking the destination folder.


All in all, my suspicion is that this may be a timing problem.

I don't know how the several actions are launched, they may be acting concurrently, and this may be the cause of the error.


I would try the following test: create a different "Test" folder, and add only one of the actions (say, the one for Music files) to this folder. Then make a script that copies some files to it, and check how it goes. I suspect that it will work correctly.


Another thing is, if my assumption above is correct: instead of several folder actions, create just one and concatenate them all - or is it that what you are doing already?



Oct 24, 2019 3:44 AM in response to Luis Sequeira1

I was thinking a little more, and doing some testing, and I came up with a different suggestion which I think is a lot more efficient.


Your workflow uses the "Find Finder Items" action, which is ignoring the given input and searching through the whole Downloads folder and all its subfolders. It should be using the "Filter Finder Items" action instead, which would apply the same criteria only to the files you are adding to the Downloads folder.

Suppose you are adding one file and the folder contains 20000 files... the difference will be significant, and the potential for issues significantly reduced with this change.



I will add similar actions for pdf, video and music files run a test creating a few thousand files and checking if they all go where intended; I will let you know.

Oct 26, 2019 11:25 AM in response to Sridhar Ananthanarayanan

I don't think you followed the important part of that.

A folder action takes in files automatically. Whatever was added is passed into the action.

Your Find Finder Items adds to those files that are pulled in automatically.


So, if you added a video file, a music file, and a jpeg image, all three would enter the workflow because that is what a folder action does.

When you then Find Finder Items, it searches the Downloads folder for files matching the criteria. If your criteria is for video files, then your workflow still has all three original files because they are passed through. That's how all workflows operate and the reason it moves files that don't meet your criteria.

That's why a Filter Finder Items is the appropriate action. Unfortunately, it has never worked correctly from what I have seen.


You can alter your workflow by disabling the connection between the folder action input and your Find Finder Items.

Ctrl-click on the triangle in the top, center of the action and choose Disable. Now, the items won't fall through the workflow.


Oct 25, 2019 10:41 AM in response to Sridhar Ananthanarayanan

I see Louis has already stated the same. However, it is not that the workflow is ignoring the things passed into it, it is processing both. That is why it is moving files to the wrong place. You could break the link between the Folder Action input and the Find Finder Items Action, then it should work as you desire.


There is no need to run a search of finder items. You are already getting files that are added to the Downloads folder when the action runs.

You are just adding another group of files to the workflow, essentially acting on the same files twice.

When the workflow runs, the files added to the folder are passed into the workflow. You then search the same folder for the music files and pass them along, too.

Files added to the folder are being moved, regardless of what type that they may be.


You need a Filter Finder Items action to do the filtering. That will filter the items passed into it, not go gather the files again.

Replace the Find Finder Items with a Filter Finder Items action.

Oct 25, 2019 10:45 AM in response to Luis Sequeira1

Barney, of course you are right that Filter Finder items is the correct action and I had said it too. But in testing I, like the OP, got very inconsistent results. Some times a file goes to the correct destination, sometimes to a wrong one, and sometimes it just stays in the folder. I’m stymied.

The Filter Finder Items has never worked reliably in the history of Automator.

I didn't see your post until after I posted the second and third paragraph. I added the first to try to clarify, then it dawned on me that you could just disable the passing of files from the Input section. But, all of this is OBE with Folder Tidy.

Oct 25, 2019 9:20 AM in response to Luis Sequeira1

I tried that too. The problem with this is it will move only one file. So if you happen to download multiple files at the same time, they may all not get organized. Thats why I switched back to find finder. The whole thing, in summary, is very unreliable. I fail to understand how such a simple thing is not being executed properly.


I have used Onyx a couple of times, and I think it forces Spotlight to reindex files. I'm not sure though.

Oct 27, 2019 10:52 AM in response to Barney-15E

In other words,


  1. Folder action itself is a trigger when a new file is added to the "watched" folder. So using Find Finder action is unnecessary.
  2. Find Finder action will simply move ALL new files from the watched folder to the folder specified by the 1st workflow that it executes.


I really can't think of how (under which circumstances) to meaningfully use this logic in a workflow.


The problem with Filter action is it will move only one file. So if the watched folder sees multiple additions at the same time, most of them will remain in the watched folder and only one gets organized in the correct folder.


Apple has to fix this.

Oct 31, 2019 3:28 PM in response to Sridhar Ananthanarayanan

Sridhar Ananthanarayanan wrote:

I don't know why you say I 'think'. Because what I said is what I 'observed' during my testing.

Since you have confirmed that these workflows are not reliable, I would rather wait for them to fix these in the OS updates. For now, Folder Tidy hopefully wouldn't disappoint.

They haven't fixed filter finder items in about a decade, so don't hold your breath.


Everything else is working as it should, you just don't understand how it works.

Oct 25, 2019 9:16 AM in response to Luis Sequeira1

I created 4 separate workflows for videos, music, pictures and documents. Spotlight seems to work fine when I try to search something.


But may be you have a point. I already purchased Folder Tidy, which is doing its job. I will test it out as you said, and post my feedback. How do you concatenate multiple workflows?


If I understood you correctly, then only 2 actions can be combined in a workflow, as far as i know. Even then, the files were being moved to the wrong folder. In fact, in my test workflow with 2 actions (find and move videos, pause, then find and move pictures), I had the video part first, then pictures. I added a video file to the downloads folder, and it was moved to the pictures folder. So the 1st part of the workflow wasn't executed (because the file in that case would have already been moved to the videos folder), and the 2nd part was executed incorrectly (because the video file was moved to the pictures folder).

Oct 24, 2019 1:56 AM in response to Luis Sequeira1

I don't think that the problem is with indexing (Spotlight) because the workflow clearly required files with specific extensions to look for and then move them into the specified folder. Indexing has no role here. Had I just stuck with the default "kind" parameter, may be indexing could be the culprit, but even then it is highly unlikely.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Has anyone successfully created an Automator script that works sensibly without errors?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.