Wednesday, August 15, 2018
  • Index
  •  » Automator
  •  » Save files to a user-chosen location at runtime?

#1 2018-08-09 02:18:40 pm

rumplestiltskin
Member
Registered: 2006-05-24
Posts: 15

Save files to a user-chosen location at runtime?

I have an Automator script that, in almost all respects, works perfectly.

Ask for Finder items - OK

Render PDF pages as Images - OK

Move Finder Items - Problem is here. Apparently, I have to specify a folder when I'm crafting the action. When I specify the Desktop, all the files generated by the previous step end up there. But I'd like the user to specify this folder during runtime. I imagine I'd need a step prior to this one where the user is asked for the folder location and it's passed to the Move Finder Items step with a variable. But I'm clueless here.

Any assistance will be appreciated. Thank you.

Barry

Offline

 

#2 2018-08-10 02:19:52 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4620

Re: Save files to a user-chosen location at runtime?

In theory, I suppose you'd use "Ask for Finder Items" again to choose the destination folder, but I can't see any obvious way — even using Automator variables — to move files to the chosen folder. My instinct, as an AppleScripter, would be to replace everything after "Render PDF Pages as Images" with "Run AppleScript", using this code in the latter:

Applescript:

on run {input, parameters}
   
   set destinationFolder to (choose folder with prompt "Choose a destination folder for the images" default location (path to desktop))
   tell application "Finder"
       move input to destinationFolder with replacing
   end tell
   
   -- input is a list of aliases, so they still point to the files after the move.
   return input
end run

Last edited by Nigel Garvey (2018-08-12 03:48:10 am)


NG

Offline

 

#3 2018-08-10 07:57:12 am

rumplestiltskin
Member
Registered: 2006-05-24
Posts: 15

Re: Save files to a user-chosen location at runtime?

Nigel,

Thank you! It has been so long since I've done anything in AppleScript that I was having trouble just trying to imagine what the code might look like. I'm sure I'm not the first person who has cursed Apple for not including this Automator action. Anyway, your code did the trick perfectly.

Stay healthy!

Barry

Last edited by rumplestiltskin (2018-08-10 07:57:31 am)

Offline

 

#4 2018-08-11 03:30:26 pm

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4620

Re: Save files to a user-chosen location at runtime?

Hi Barry.

If you're still checking this thread and are interested, I've just been watching a video of a talk about Automator and have come upon a couple of similar but different solutions.

The first is a cross between what you originally wanted and the Run AppleScript solution:

1. After Render PDF pages as Images, insert Move Finder Items as you originally intended.
2. Click on Variables in the top left corner of the Automator window and drag the variable called AppleScript onto the To: pop-up menu in Move Finder Items.
3. Click the menu and choose Edit….
4. In the dialog which opens, replace "Text" in the Script field with:

choose folder with prompt "Choose a destination folder for the images" default location (path to desktop)


5. Give the variable a different name if you like and click Done


The other's method's longer, but doesn't involve any AppleScript:

1. After Render PDF pages as Images, insert Set Value of Variable. This will store the images for later retrieval.
2. After that, insert Ask for Finder Items. Set it up for type "Folders" and set the Prompt: and Start at: values as required. Under Options, check "Ignore this action's input".
3. After that, insert another Set Value of Variable, choose New variable… from the pop-up menu, enter a new name (say, "Destination Folder"), and click Done. This is obviously to store the folder chosen by the user.
4. Then insert Get Value of Variable and, select the name of the variable holding the images in its pop-up menu. Under Options, check "Ignore this action's input".
5. Finally, insert Move Finder Items and drag the name of the "Destination Folder" variable from the variable list at the bottom of the window onto this action's pop-up menu.


If I find a non-AppleScript method involving fewer actions, I'll post it!


NG

Offline

 

#5 2018-08-11 04:24:35 pm

rumplestiltskin
Member
Registered: 2006-05-24
Posts: 15

Re: Save files to a user-chosen location at runtime?

Nigel,

Yes; I always keep the subscription to a thread here active simply because you never know when someone is kind enough (you, in this case) to provide add'l helpful material. Thank you very much!

When I started with this little project, I found that the text prompts Automator used to provide are no longer present in Sierra (I read that happened a few macOS upgrades ago) so the add'l AppleScript prompt before the dialog appears works around that deficiency.

Regards,
Barry
smile

Offline

 

#6 2018-08-12 03:50:29 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4620

Re: Save files to a user-chosen location at runtime?

rumplestiltskin wrote:

the text prompts Automator used to provide are no longer present in Sierra


Hmm. I didn't notice that. The prompt parameter's still there in the action, so the lack of a prompt in the dialog must be a bug.

An equivalent AppleScript to ask for the PDFs at the top of the workflow would look something like this:

Applescript:

set output to (choose file of type {"com.adobe.pdf"} with prompt "Select the PDF file(s) you want to process" default location (path to desktop) with multiple selections allowed)

return output

I've added a comment to the script in post #2 explaining that returning input as the output is in fact correct.  smile


NG

Offline

 

#7 2018-08-12 09:41:32 am

rumplestiltskin
Member
Registered: 2006-05-24
Posts: 15

Re: Save files to a user-chosen location at runtime?

Nigel,

Last I heard, this bug was never going to be fixed.

Thank you, though, for your update to post #2. I tend to comment my code liberally (I normally use Livecode) as I'll never remember what I was attempting to do when I come back to it six months later. big_smile

Regards,
Barry

Offline

 
  • Index
  •  » Automator
  •  » Save files to a user-chosen location at runtime?

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)