Use AppleScript to return path name

I have multiple files selected in a folder and I need AppleScript to return the path of that folder. I am then passing it along to a Variable and using the Variable to set the save location of my workflow.


On another site I found it said to use this:

tell application "System Events" to return name of (item 1 of input)


But that results in an error later in the workflow. The problem is it returns the path multiple times... so if there are 4 files selected the path is returned 4 times and the save location is invalid.


How do I get it to return ONE path?

Posted on Jan 29, 2015 2:44 PM

Reply
16 replies

Jan 29, 2015 3:14 PM in response to Niel

Hi, the resulting file ends up on the desktop and doesn't go into the folder.


The script:

on run {input, parameters}

tell application "Finder" to return parent of item 1 of (selection as alias list)

end run


Then "Set Value of Variable" with the name containerPath.

At the end when I need to move the file:

Move Finder Items to containerPath


I'm not getting any errors, just the file correctly processed on the desktop.

Jan 29, 2015 4:44 PM in response to Niel

Sure I will post it tomorrow as it's at work and I've gone home. I assume I need to host it somewhere and post the link; there's no way to directly share a file here?


Side note: quite frustrating, after I has edited the workflow with your suggestion now it doesn't save the file at all to the desktop even though I reverted it back to before the changes - I still get an error near the end. Hopefully if you take a peek it will be more clear.

Jan 30, 2015 9:08 AM in response to Tony T1

It's a long workflow so it's in 3 parts. What I need to accomplish:


- convert a selection of EPS files to PDF

- select the resulting PDF's and combine into one

- rename the combined PDF so it matches the originating folder

- move the combined PDF into the originating folder

- BONUS if anyone knows who to tell it to delete the single PDF files but not a biggie

User uploaded file

User uploaded file

User uploaded file

Jan 30, 2015 11:17 AM in response to Jeremy Bohn

Instead of your existing workflow, run the following AppleScript action:


on run {input, parameters}

tell application "Finder"

set originalPDFs to get every file of entire contents of target of window 1 whose name extension is "pdf"

set containerPath to container of item 1 of originalPDFs

set containerName to name of item 1 of containerPath

set posix_PDFs to ""

repeat with this_PDF in originalPDFs

set posix_PDFs to posix_PDFs & quoted form of POSIX path of (this_PDF as alias) & " "

end repeat

set posix_PDFs to items 1 thru -2 of posix_PDFs as string

set posix_dest to "'" & (items 1 thru -2 of POSIX path of (containerPath as alias)) & "/" & name of containerPath & ".pdf' "

do shell script "python '/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py' -o " & posix_dest & posix_PDFs

delete every item of originalPDFs

end tell

end run


(121264)

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 AppleScript to return path name

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