Not sure if this is even possible, but I’d like to ask just in case.
Here’s the scenario (scroll to bottom image for visual reference, unfortunately i have to consolidate everything into a single image as I am a new user…I sort of get the logic of this but it’s pretty annoying!)
So obviously I know in finder i can get the path of a selected item or folder quite simply through
tell application "Finder"
set selItem to the selection
set posixPath to POSIX path of (selItem as text)
end tell
For example in my case i created this test folder (part A of the only image I am allowed to upload)
I then set the clipboard to posixPath, and i have myself a quick action that copies the POSIX path of the selected item. All good.
My dilemma is this, what if i wanted to copy the path of one of the items in path bar? Is there any way in AppleScript to reference the element which is being right clicked in the pathbar? I couldn’t for the life of me find anything about it.
As a visual example, in part B of the image, i’d like the script to copy the path up to the right-clicked folder in the pathbar so the clipboard would store “/Users/Test/” (ignore that Test is the active folder in this example, my objective is to get the path of any right-clicked folder in the path bar).
Let’s also ignore for now the fact that we’d still have a selection active in finder which we’ll have to deal with, for now i’d only like to know if there’s a way have the script read the path bar “selection”.
here’s the image for reference
Many thanks for any contribution!
Cheers
What is your goal here?
There’s no inherent access via AppleScript to that item in the path bar, at least not via AppleScript.
As far as the Finder is concerned, selection always relates to the selected file(s)/folder(s), not arbitrary UI elements.
However, if you’re just trying to get the folder the selected item is in, that’s easy:
tell application "Finder"
set selItem to (get selection)
if selItem is not {} then
set itsFolder to container of (item 1 of selItem)
end if
end tell
You can use a Run AppleScript
action in an Automator Quick Action (service) for both - a list of aliases will be passed to the workflow, which the action will receive in its input
parameter. Set the workflow to receive files or folders in the Finder and it will appear under Services
in the path bar contextual menu, and under Quick Actions
in the Finder contextual menu.
Play with this script…
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
property myProps : {}
local myRow
set myRow to false
tell application "System Events" to tell application process "Finder"
repeat while exists window 1
try
set myRow to false
tell outline 1 of scroll area 1 of splitter group 1 of window 1
repeat with c from 1 to count rows
if selected of row c then
set myRow to row c
exit repeat
end if
end repeat
if myRow = false then
delay 0.5
else
if exists menu 1 then
tell me to say (value of static text 1 of UI element 1 of myRow) & " Is right clicked"
else
tell me to say (value of static text 1 of UI element 1 of myRow) & "Is Selected"
end if
end if
end tell
on error
beep
end try
end repeat
end tell
First of all thanks for your reply!
We have a software that copies the path of an item and converts it to windows format (WinShortcutter), as well as allowing us to navigate to locations shared with us in windows format, but I wanted to try to do it via AppleScript as an exercise to start learning.
I managed to do both things perfectly, and annoyingly the only limit of applescript vs that software so far is the inability to copy from the path bar, which is quite handy because at any point i can copy the location of any level of the current volume with a simple right click.
You are probably right though that this is simply a limit of AppleScript.
That looks interesting.
I only partially understand what’s happening at a glanc, but I will definitely try to decode it tomorrow.
Many thanks!
This may not be the solution you are looking for, however, this may be something you will find useful. I know I find it useful.
This following AppleScript will take the items selected in the front Finder window. It will then present you with a list to choose from, which contains the path to every containing folder, then copy your chosen path to the clipboard.
In the Shortcuts app I created a new shortcut with the AppleScript code so anytime while I’m in Finder and I have an item selected I could simply run the shortcut from the shortcut menu bar which will give me the option to copy the path of any of the containing folders of the selected item to my clipboard.
set theContainers to {}
tell application "Finder"
set selectedFolder to item 1 of (get selection)
set containingFolder to container of selectedFolder
set end of theContainers to selectedFolder as alias
set end of theContainers to containingFolder as alias
repeat
try
set containingFolder to container of containingFolder
set end of theContainers to containingFolder as alias
on error errMsg number errNum
exit repeat
end try
end repeat
end tell
activate
set theChoice to (choose from list theContainers ¬
with title "Folder Path To Clipboard" with prompt ¬
"Choose An Item To Place Its Path On Your Clipboard" OK button name ¬
"OK" cancel button name "Cancel")
if theChoice = false then return
set the clipboard to POSIX path of theChoice
This following image shows how I set this up in the Shortcuts app
This following animation demonstrates the shortcut in action.

This COULD work, IF i found a way to access the pathbar items, then, even if effectively the UI only reads the name of thar folder, i could reconstruct the path based on location information from the current active finder window.
But for the life of me i can’t, i can’t even get to work the damn UI Browser on my mac 
Well, this is suuuper interesting!
It’s a nice workaround, although under the perspective of creating a script to save a couple clicks on repetitive tasks, unfortunately on its own it doesn’t hit the brief, but I thank you very much for providing a further learning experience with an approach that I hadn’t thought about at all!
Here is another solution which, if you ask me, is probably the simplest solution using the least amount of code.
In Script Editor, use this following AppleScript code and save it as an application. Then just place that application in your Dock. Now all you need to do is drag any file or folder from anywhere in the Finder window to your new AppleScript application which you placed in the Dock, and it will place that item’s Posix path on your clipboard.
on open theFiles
set the clipboard to POSIX path of theFiles
end open

if you use this following code instead…
on open theFiles
set the clipboard to POSIX path of theFiles
end open
on run
activate
display dialog (the clipboard) buttons ¬
{"OK"} default button "OK" giving up after 4
end run
After you drop an item onto the app’s icon in the Dock, which copies that items POSIX path to your clipboard, if you simply just click on that app icon in your Dock, it will display a Dialog window showing what is on your clipboard.
