Is there a way to programmatically access the name of the folder that appears when the choose file dialog window is open?
For example, it comes up if you press cmd+O in your browser or have to choose a folder location when saving a file. Thanks!
Is there a way to programmatically access the name of the folder that appears when the choose file dialog window is open?
For example, it comes up if you press cmd+O in your browser or have to choose a folder location when saving a file. Thanks!
Do you mean the name in the top of the window (Desktop in your screenshot)? If so, I can't think of any way to get that folder, short of perhaps seeing if it's saved in each app's Settings file (because it will vary by app).
Edit: As usual, @Nige_S' AppleScript wizardry to the rescue!
From a problem view, why do you need that value? Perhaps there's another way to accomplish whatever it is you're trying to do.
-rob.
This generally works:
tell application "System Events"
set theApp to item 1 of (get every application process whose frontmost is true)
tell theApp
return value of pop up button "Where:" of window 1
end tell
end tell
But the name itself isn't worth much. Just because a folder is called "Desktop" doesn't mean it's the Desktop!
I tried this in a few applications, but I'm getting this error. Any ideas why?
Action 100974166 failed: Execute an AppleScript failed with script error: text-script:136:141: execution error: System Events got an error: Can’t get pop up button "Where:" of window 1 of application process "Brave Browser". (-1728)
In some apps the dialog is a sheet of the window, looks like Brave is one:
tell application "System Events"
tell process "Brave"
return value of pop up button "Where:" of sheet 1 of window 1
end tell
end tell
--> "nigel"
So try expanding the script to
tell application "System Events"
set theApp to item 1 of (get every application process whose frontmost is true)
tell theApp
tell window 1
if exists sheet 1 then
return value of pop up button "Where:" of sheet 1
else
return value of pop up button "Where:"
end if
end tell
end tell
end tell
Of course, this is being tested on macOS 15 -- there may be more nesting, or missing names, or other silliness in macOS 26!
As @griffman asked earlier -- why do you want to do this? It won't be very reliable for decision-making without a complete path, for example.
Still getting an error on macOS 26.
2026-03-13 11:25:00 Execute an AppleScript failed with script error: text-script:180:185: execution error: System Events got an error: Can’t get pop up button "Where:" of sheet 1 of window 1 of application process "Brave Browser". (-1728). Macro “Test” cancelled (while executing Execute AppleScript).
My goal with this is that I have a couple of macros where I want to change the folder from the choose file dialog.
I've been doing it using Command Shift G, then inserting a path, but if the appropriate path is already the frontmost folder, then I want to skip that step.
So if I can check what the frontmost folder is, then I can skip that step and save a second or two on the macro.
But you're only checking the name, not the path, so there's a chance of error unless they're unique across all your volumes. You can get the path by popping the dropdown and collecting all the folders listed and building your own path -- but at that stage it's almost as quick (and certainly easier!) to just set the path every time.
All that said... It looks like Tahoe has wrapped the part of the dialog we want in a splitter group, and you'll need to add that to both parts of the if block:
if exists sheet 1 then
return value of pop up button "Where:" of splitter group 1 of sheet 1
else
return value of pop up button "Where:" of splitter group 1
end if
If you use Default Folder X, your macro could contain a Type a keystroke action to simulate the key combination ⇧⌘ C (or whatever your preferred hotkey may be) to copy the path, and then use a Search regular expression action to get the end of the path after the last / by matching .*\/(.*)
Perfect, thanks.
I know it will be unreliable, but this will work for my needs.