Automator: using a text file to define multiple finder items?

Hello,


what i would like to do:


i have a text file, that contains several entries for files and folders, each on a seperate line. I want to dragndrop this file onto an automator action, it should ask me for a destination folder and then copy all files&folders to that destination folder.

I have my automator action set up like this:


Open Finder Items

Get Contents of TextEdit Document

Copy to Clipboard (i didn't find any other way to somehow keep the values of my textfile and let it not be overwritten by the following actions, but this works)

Quit Application (TextEdit)

Ask for Finder Items (this asks for a destination folder)

Set Value of Variable (Destination)

Get Contents of Clipboard

Copy Finder Items (to Destination)


This all works, but only when there is 1 entry in my text file. As soon as i have 2 lines of text i get the following error message:

The action "Copy Finder Items" was not supplied with the required data.


How can i make this work with multiple entries?

MacBook Pro, OS X El Capitan (10.11.2)

Posted on Jun 15, 2016 8:52 AM

Reply
4 replies

Jun 15, 2016 11:46 PM in response to Daniel Hartlehnert

The problem is that you are only passing the one item to the copy action (the text you copied), instead of an item for each line (paragraph) in the text. The solution is to use the Filter Paragraphs action to break up the text along paragraph boundaries, which will give you a list of items. Also, you don't necessarily have to use TextEdit or the clipboard - if you already have a file somewhere, you can just use the Combine Text Files action to read the text.


With the above changes, your workflow would look something like:


Ask for Finder Items (ask for a destination folder)

Set Value of Variable (Destination)

Ask for Finder Items (get the text files) -- set the action's option to ignore input

Combine Text Files (read the text files)

Filter Paragraphs (return paragraphs that are not empty)

Copy Finder Items (to Destination)

Jun 15, 2016 11:58 PM in response to red_menace

Hi,


i tried the workflow you suggested, but i get the same error message. 😟

Besides, i would like to be able to just dragndrop my textfile onto the automator script, thats why i want to do it as a program, not a workflow.

This means i have to read the contents of my textfile as the first action, define the output folder, then doing the copy action to the destination.

So again i have to somehow save the entries in my textfile while not being overwritten with the output folder action.

Your post gave me some interesting insights though:

I didn't know "Combine Text files" reads the contents of the file. "Combine" is a bad acronym for "reading" 😕 I just thought it, well, combines several text files.

Also, i already guessed the original problem was that automator sees the text as one item instead of several items. So i knew i have to somehow define a list of items, i just couldn't figure out how. Therefore, i played around with "Filter Paragraphs", but it just didn't do anything for me.


One additional question came up:

When using Ask for Finder Items, in Automator you can give it a message like "Please choose a text file" so the user knows what he is supposed to do.

But, when the file requester comes up, i cannot see this message anywhere?

Jun 17, 2016 2:29 AM in response to Daniel Hartlehnert

Sorry, I forgot how goofy Automator is - the error comes from some actions not handling text/rich text the way they should. A workaround for that is to add a Run Shell Script action (the default setting just outputs plain text). You can also use another variable to stash the original input until you are ready, so the application (tested on my Yosemite system) now looks something like:


Application receives files and folders as input

Set Value of Variable (Input) -- stash the original input

Ask For Finder Items (set option to ignore input) -- the destination folder

Set Value of Variable (Destination)

Get Value of Variable (Input - set option to ignore input) -- get original input back

Combine Text Files -- this also filters out non-text files

Run Shell Script (leave the default settings)

Filter Paragraphs (return paragraphs that are not empty)

Copy Finder Items (to Destination)


Note that your text file needs to contain paragraph delimited valid POSIX paths, and your application will need to be added to the System Preferences > Security & Privacy > Privacy > Accessibility tab to give it permission to do its thing.


The text entered into the Ask For Finder Items action works for me, so I don't know what is happening there.

Jun 17, 2016 3:02 AM in response to red_menace

Hi,


great, this works! 🙂 Thank you very much, because i would have never figured out that i need to use Run Shell Script to make this work.


Couple of notes though:


- while the automation is running, i noticed the little turning cogwheel in the top finder bar. The % goes way over 100%. I don't see a finder progress bar like i would if i copied the items by hand. This would be more accurate showing me how much is copied. Is this possible?


- the following image is what i see when the file requester comes up to ask for the destination folder:User uploaded file


I would expect the text i entered for this action ("Please select the destination folder:") to appear at the top bar of the requester, but its not there? You mentionend it works for you? (i found a workaround for now by using a wait for user confirmation action before the file requester comes up)


- The file requester doesn't come to the front, it could be hidden behind other finder windows 😟

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.

Automator: using a text file to define multiple finder items?

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