Use text as Automator variable to find files and sort them into subfolders

Hello,


I have been long looking for a solution to a problem succinctly stated as in the title.

I want to say first that I am not good at scripting so please, be patient with me.


I have plenty of files—PDFs—within the same folder.

Their filename usually can have a pattern like this, 'XYZ... NAME SURNAME..XYZ' or like this, 'XYZ... SURNAME, NAME XYZ', where 'XYZ' is any string of text of no importance in this context.


What I would like to achieve is having an Automator service or quick action which, after asking for some text—namely what I know being those NAME and/or SURNAME—would prompt a search for each and every item containing those words, their collection and sorting within the same subfolder and the naming of that subfolder after the words adopted.


I hoped to do this with Automator and using variables but unfortunately variables are useless with either 'Find Finder Item' and 'Filter Finder Item' actions.


Any help would be very much appreciated.

Thanks for reading.

Posted on Dec 11, 2022 10:41 AM

Reply
5 replies

Dec 15, 2022 4:09 PM in response to teobalsamo

teobalsamo wrote:
Automator's commands 'Find Finder Items' and 'Filter Finder Items' don't work with variables because they don't accept them.


They do, but its not intuitive.

Need to "Set Value of Variable" after "Ask for Text" to set the variable.

Then, before "Find Finder Items", need to "Get Value of Variable", which is then passed to the next action "Find Finder Items (as you found out, you can't drag to variable into the search box):


In this example, I have a file named "test.txt" on my Desktop, and the Automator Workflow searches the Desktop:


Dec 13, 2022 4:10 PM in response to teobalsamo

Hello teobalsamo,


If you have not already done so, you may want to take a look at the Automator User Guide for Mac - Apple Support to see if it offers information on the search actions you're trying to achieve.


The "Do more with Automator" drop-down offers more information about variables, adding variables, workflows, and much more.


About variables in Automator on Mac - Apple Support

A variable is a named container that is used to temporarily store information to use when needed. Variables can contain all types of data, such as text, a reference to a file, or a list of object references. You can refer to the same variable from action to action or workflow to workflow, although the information within it may be different. For example, the date may change, although the variable Today’s Date remains the same.

You can add a variable to an action or to a workflow.

Some variables in Automator are constant values—for example, “Today’s date” or “My name.” Automator temporarily holds a value while a workflow runs.

Some actions may allow you to choose a declared variable from a pop-up menu. Other actions give you the option to create a new variable from a pop-up menu.

See Add variables to an action and Add variables to a workflow.


Best wishes!

Dec 15, 2022 3:26 PM in response to genieen16

Hello genieen16,


Thank you for having replied to me.


I had already looked into that guide actually and didn't found what I am looking for. What is given to help building up Automator's workflows is not as complex as I need.


The fact is that I cannot deal with scripting because I don't know anything about it. I would need somebody's patient help as to give me a solution or putting me on the correct way to it.

In other words I need to be told how to build a script (either a Shall script or an Apple script) which would be fed up with variable values asked for with a proper query a step before ('Ask for text input' command) and use those variables so to find, get and sort into subfolders as many files as corresponding to given criteria.


I think that Shortcuts could do in my case because it works with variables in a more extensive way than Automator but unfortunately my machine is a bit old and I can work with Automator only.


Automator's commands 'Find Finder Items' and 'Filter Finder Items' don't work with variables because they don't accept them.

That's why a script is the only solution and why I am here begging for it.

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.

Use text as Automator variable to find files and sort them into subfolders

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