Automator “Filter Finder Items” issues with spotlight

automatorfinderspotlight

When using an automator workflow with the following actions:

  • Get Specified Finder Items (some zip files)
  • Open Finder Items (with an unzipping utility)
  • Move Finder Items (to an existing folder)
  • Filter Finder Items (i.e. excluding folders)

I get mixed results, most of the time the filtered Items are incomplete. Some of the latest unzipped files are missing from the "Filter Finder Items" results.

I learned here that this specific action uses spotlight to provide the results. So this makes sense, as the newest files created might still not be indexed a few seconds later.

So the question is, how can I make sure that the parent folder or the files are properly indexed before using the "Filter Finder Items" action?

I've tried using the "Pause" action, but depending on the hardware or system load, we are quickly in the tens of seconds to have an uncomfortably uncertain reliability of this workaround.

How could we solve this? Any help appreciated

Best Answer

You add a shell script as the first automator task to run sudo mdutil -E /. This will rebuild the index.