Saving To Original Folder In Automator

Hi everyone,

I'm working on an automator action in Snow Leopard to convert a bunch of small groups of images that I have to single PDF files with multiple pages. What is want it to do exactly is take an input of several files, turn them into the pages of a PDF, then give that PDF the name of the first file and then save it in the same folder as the first file, or something to that effect. Essentially I need the output to go to the same location as the source and to have the same name as any one of the files. It seems really simple, but I've googled and dug around Automator to no avail; I've managed to get every step except saving the output file where I want it. Does anyone have any idea about how to do this?

The other ideal thing would be for it to run through a folder and go into all of its subfolders and combine each group of images into a different PDF file. In other worlds, if folders B and C are inside folder A, I can select folder A and it will go into folder B and make a PDF out of all of the images inside folder B and then go into folder C and create a PDF out of all of the images in folder C, etc. This sounds like it would be much more complicated, so I'm not getting my hopes up, but if anyone has any ideas about doing this also I would greatly appreciate it!

Thanks!

Intel Macbook, Mac OS X (10.6.2)

Posted on Feb 1, 2010 8:38 PM

Reply
11 replies

Feb 1, 2010 9:24 PM in response to Faelen

Faelen wrote:
Hi everyone,

I'm working on an automator action in Snow Leopard to convert a bunch of small groups of images that I have to single PDF files with multiple pages. What is want it to do exactly is take an input of several files, turn them into the pages of a PDF, then give that PDF the name of the first file and then save it in the same folder as the first file, or something to that effect. Essentially I need the output to go to the same location as the source and to have the same name as any one of the files. It seems really simple, but I've googled and dug around Automator to no avail; I've managed to get every step except saving the output file where I want it. Does anyone have any idea about how to do this?


this can be done using automator variables and "run applescript" action.

make your workflow like this
1. get selected finder items
2. run applescript
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #ADD8E6;
overflow: auto;"
title="this text can be pasted into the Script Editor">
on run {input, parameters}

tell application "Finder"
container of item 1 of input
end tell
end run</pre>
this action returns the ambient folder for the first item in among the selected items in finder.
3. set value of variable
make a new variable here (call it "ambient-folder" or something) and assign the output of the previous action to it.
4. get selected finder items. control-click on this action and select 'ignore input' to break the chain of actions.
5.run applescript
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #ADD8E6;
overflow: auto;"
title="this text can be pasted into the Script Editor">
on run {input, parameters}

tell application "Finder"
set current_ext to (name extension of (item 1 of input)) as text
set fname to text 1 thru -((length of current_ext) + 2) of (name of (item 1 of input) as text)
return fname --return the name of the first item in the list
end tell
end run</pre>
6. set value of variable "new-folder-name"
7. get selected finder items. again, control-click on it and select 'ignore input".

From here do your workflow. in the action where you make a new folder drag the variable "ambient-folder" you used earlier to the "where" field of the "new folder" action so that the new folder will be created in the right place. and drag the variable "new-folder-name" to the folder name field.

Feb 2, 2010 3:25 PM in response to Faelen

Thank you so much! I figured that Applescript would be the answer to my problem (this is when I wish I knew how it works), but I think what you're saying isn't exactly what I want to do. I don't want to create a new folder, I just want to put it in the same folder that the input files came from. And I want it to share the same name as one of the input files. I'm using the automator action New PDF From Images, which unfortunately asks for the name and destination, which is making it complicated.

I tried tweaking what you showed me a bit but I couldn't manage anything. Do you have any other advice? It'd be really great.

Feb 2, 2010 3:34 PM in response to Faelen

sorry, misunderstood you. but that's easy too. keep steps 1-4 same as I made them. change step 5 to the following applescript
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #ADD8E6;
overflow: auto;"
title="this text can be pasted into the Script Editor">
on run {input, parameters}

tell application "Finder"
set current_ext to (name extension of (item 1 of input)) as text
set fname to text 1 thru -((length of current_ext) + 2) of (name of (item 1 of input) as text)
return fname&".pdf" --return the name of the first item in the list but change the extension to pdf
end tell
end run</pre>
6. set value of variable "new-pdf-name"
7. get selected finder items. again, control-click on it and select 'ignore input".

next do your workflow. on the action 'new pdf from images" drag the variable "ambient-folder" in the "where" field and the variable "new-pdf-name" in the name field.

Feb 2, 2010 5:56 PM in response to Faelen

Faelen wrote:
Almost there! The first applescript runs into a syntax error: Can’t make «class ctnr» of item 1 into type reference.

I don't get any errors when I run it. but try this
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #ADD8E6;
overflow: auto;"
title="this text can be pasted into the Script Editor">
on run {input, parameters}

tell application "Finder"
container of (item 1 of input) as alias
end tell
end run</pre>

Also, I can't drag the variable to the name field in the Create PDF from images field;

that's bad. then there is no way to do it, period. you'll have to reconsider your workflow requirements.
when I try, it just adds it to the end as a new action, Get Value of variable.

Feb 2, 2010 6:19 PM in response to Faelen

I've almost got it! I found this thread, which showed me how to use variables in the name field:

http://discussions.apple.com/thread.jspa?messageID=6596255

So I went in and found the UUID string line, and copied it and pasted it into the name field. Now it seems like everything should be working exactly the way I need it to, but for some reason when it runs, nothing happens. Any ideas on what the problem might be? I've uploaded it here for troubleshooting:

http://www.4shared.com/file/214043611/4f52d850/CreatePDF_FromImagesapp.html

Feb 2, 2010 8:27 PM in response to Faelen

ok, I took a look at your app. first, if you save it as an application and invoke it by dropping some files on it then you should get rid of the very first 'get selected finder items" action. it's redundant and only messes things up. those files are passed to the flow already. i also played with the script and it seems that the action to make new pdfs from images is buggy and won't accept a variable in the "where" field properly. if you change it to point to a fixed folder then everything works. the trick you found for using variables in text fields that don't accept variables is very nifty. it does work too. it's the other part that is broken. I don't see any way around this.

Feb 2, 2010 9:13 PM in response to Faelen

Okay. What about using the Move Finder Items action? I'm trying to use that with a a variable, so it can just put it somewhere like the desktop and then move it, the issue is I keep getting applescript errors so nothing will run correctly...

By the way, thank you so much for all of your help V.K.! I really appreciate it

Feb 2, 2010 9:23 PM in response to Faelen

yes, move action ought to work. I should have thought of that. make some fixed folder which should be kept empty. make the new pdf action save files in that folder. then add the action to move finder items at the end of the workflow and put the "ambient folder" variable into the destination field.

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.

Saving To Original Folder In Automator

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