How to detect that the frontmost window is a modal open/save dialog box?


I have a macro that opens favourite folders I have, in 2 possible ways:

  • If I'm working in any application, it will open the Finder window I choose;
  • If I'm in an application and I want to open or save a file (and the corresponding open or save dialog box is frontmost), it will open that folder in the dialog box, so I can save my file directly where I want it to be.

My problem is detecting in which state the application is: is the frontmost window a "normal" window (like a spreadsheet, a browser window, a Word document...) or is it an open or save dialog box? Because it seems to me that applications behave differently when it comes to reporting on such a dialog box...

E.g. when using the name as a property, the open or save dialog box is called "Microsoft Excel" in Excel (a normal sheet would be called e.g. "Revenues 2019" or whatever), has no name in Chrome and so on.

So now I'm using a series of "any condition met" steps:

  • Name is empty
  • Name is "Microsoft Excel"
  • A "New Folder" button is present (like you often, but not always, see in such dialog boxes)

All this is fine by me, but isn't there a smarter way that is more definitive?

Thanks & cheers --Mike

I'm sure you can further optimize your KM Macro, but let me suggest that you consider a great tool for providing quick access to files/folders from everywhere: Default Folder X.

I use KM extensively many times a day, but DFX really makes all of my access to files/folders very fast and easy.

Having said that, it is very easy to test for an "open file" dialog. Here's an example Macro to illustrate the method:

MACRO:   Using Finder Go To Location Shortcut in File Open Dialog

~~~ VER: 1.0    2019-03-08 ~~~


Using Finder Go To Location Shortcut in File Open Dialog.kmmacros (5.8 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


Hi @JMichaelTX,

Thanks for your answer. I've looked DFX, but for me it's overkill and when I tested it some years ago I found it a bit slow... Also, with my method I'm able to use nothing but keyboard shortcuts (using palettes for choice). Works fine for me.

I must say that when reading that macro I'm not sure how it tests if the front window is a modal open or save window?

Thanks & cheers --Mike

I agree with @Michiel here (particularly about Default Folder, which I found to be cumbersome and overkill for my needs).

I have a simple macro that switches to the Finder and opens a specific folder. I want to add a function to it that checks to see if there is an Open or Save dialog box frontmost; if there is then I'll have it navigate to the correct POSIX path there using the Cmd-G/Go/Insert Text sequence.

Is there a simple way to determine if a dialog box is the frontmost window?

TIA to everyone reading/replying.

A macro that uses the If Then Else action to look for a Cancel button like in an Open/Save dialog would probably work. If the button is present, proceed with the Command-G option or else just open the Finder folder. Alternatively, a menu condition might work in the same way, such as whether File > Open is enabled (or any menu item that toggles between enabled/disabled when an Open/Save dialog is activated).

That is a very good suggestion! I'll see whether this works. Thanks, @NaOH!

Cheers --Mike

@NaOH - Yes, that worked. (File under: Duhhh - why didn't I think of that??). Many thanks.

For anyone interested the macro that I've written performs a simple function that has been a real nuisance for me for years (isn't that what macros are for?). I often want to navigate to a specific folder in either the Finder or in a dialog box. It's either the Downloads folder, which I've illustrated here, or my "Pending" folder, which works identically but simply takes me to that folder instead.

The nuisance was that if I wanted to open the Downloads folder in the Finder I'd have to switch to the Finder and either click the sidebar or use the keyboard command that I created in the Keyboard>Shortcuts Preferences pane for the Downloads folder. Not a big deal but when I want to open that same folder in an Open/Save dialog box it always required a mouse click on the sidebar or the Go-To-Folder keystroke (Cmd-Shift-G) and then entering the pathname (~Downloads) and hitting return.

This macro (now, thanks to NaOH) detects whether there's an Open/Save dialog box open and, if so, switches to the Downloads folder. If a dialog box is not open it switches to the Finder, opens a tab (to avoid multiple windows) and goes to that folder.

I've got several of them set up now for different folders (Pending, Screenshots, whatever) that I go to frequently in the Finder or Dialog boxes and they can all be reached with different keystrokes. A real timesaver.

Thanks to the community here for reviewing and again to NaOH for the spot-on suggestion.
Go To Download Folder.kmmacros (4.9 KB)

That's exactly the idea behind my macro too. If a Dialog box is open, then go to that folder, if not, go to Finder & show that folder. I've put several of those folders I want in a palette for easy choice.

And indeed NaOH's idea should be filed under Duh why didn't I think of that :smiley:

Cheers --Mike

Most built-in keyboard commands shown in the Finder > Go menu work in Open/Save dialogs.


The All My Files shortcut does not work, Desktop in an Open/Save dialog becomes Command-D, but Command-Option-L for Downloads works (among others).

Hi @Scott721
I have been using a Macro that I worked out over several attempts that does exactly what your Macro does - but is different in three details.

  1. When you make a copy of your Macro and use it as a template for going to another folder, you have to enter the folder's path in two Actions in the Macro. I was doing this as well until I realised I could use a variable so that I only had to enter the path once in one single Action. So, you enter the path in the first Action and then as the Macro runs it takes care of that throughout the rest of the Macro.
  2. I found it is helpful to have a "pause until" action after the Go To action as sometimes the Macro started pasting in the file path before the "Go To" window was open. Pausing until a button with "Go" enabled achieves this.
  3. There is already a built-in Action in Keyboard Maestro to go to a folder in the Finder so, you can use that for the second bit of the Macro instead of having to replicate lots of keystrokes.

This is probably the Macro I use the most everyday to navigate around my Mac.

In the screenshot below, the Green coloured Action is the only place you have to put the path to the folder or file you want to open. I've also uploaded the actual Macro.

Go To Download Folder (Zabobon).kmmacros (4.4 KB)

For things like this I like to use a single macro with multiple hotkey triggers. I then switch (e.g. the folder variable) based on the %triggervalue%. That way I can update the logic without having to update multiple almost identical macros. The one downside I've found is the hotkeys don't all show up in palettes or the editor window (second column)

It's actually extremely quick to make a duplicate of my "template" Macro, name the duplicate as the new folder, assign a new hotkey (I use a trigger system of ⌃⌥⌘ and a letter where the letter is the first letter of the folder or file name) and then paste in the path to the folder or file in the single green action of the above Macro. I don't worry about having the same shortcut to two different folders as the Conflict Palette takes care of that. And I only do it for folders or files I find I'm opening a lot.
I've tried various systems over the (actually it must be years now) and so far, this works the best for me which is why I wanted to share it.

Thinking about it... I might make a Keyboard Maestro Macro to automate the steps in creating new Macros based on this system... This is the only problem with Keyboard Maestro - making Macros and tinkering with them is addictive :slight_smile: