To press a button in a dialog using a keyboard shortcut, press Command, followed by the first letter of the action you wish to trigger. The exception to this rule is if the action you wish to activate will delete a file or changes thereto, in which case the shortcut is Command-delete.
To force-close a window, you'd need to automate the correct series of key presses using AppleScript or something similar. The first key combination would likely be Command-W (though not even this is entirely universal). However, the dialog shortcuts vary by application—older versions of Microsoft Word don't comply with the Command-delete behavior (they use Command-D), while Automator's save sheets can often only be closed through mouse input. You would have to tailor this behavior to the specific applications in which you're interested. Such an AppleScript might look something like this (though be warned, triggering Command-delete without knowing the context is an easy way to accidentally delete files and large swathes of text):
tell application "System Events"
keystroke "w" using {command down} -- Command-W
delay 0.5 -- Wait for the dialog to appear
key code 51 using {command down} -- Command-delete
end tell
To tie an AppleScript to a keyboard shortcut:
- Open Automator (Applications > Utilities > Automator) and create a new Service (optionally, configure it just to run in the applications you want).
- Add a "Run AppleScript" block in which you write your AppleScript.
- Open System Preferences > Keyboard > Shortcuts.
- Create a new shortcut, where the "Menu Title" is the title you gave your Service (again, you can tie this shortcut just to the applications to which your Service applies). The keyboard shortcut you enter here is the one you can use to trigger your "force close" behavior.
You could create multiple services, each one with the same keyboard shortcut but in different applications, corresponding to the unique behavior of each.
Answer from aaplmath on Stack ExchangeWindow won’t Close - Apple Community
macos - How to close a window without the application quitting? - Ask Different
Minimizing and closing windows in MacOS - Apple Community
Can someone help please! This window is stuck open like this (I think it was ever since I opened Keynote) but it won’t leave, close or even appear in the activity monitor. How to get rid?
You always have the option to hide the active program. When the application in question is active (in front of all others) there are 2 options:
- option ⌥+click on the Desktop
- command ⌘+h
The first option always works or at least I can't think of any exceptions this minute. The second is supported by most applications.
In either case:
- Your session will be preserved.
- Neither will cause these windows to be displayed in the Dock where the minimized programs are located.
- You'll need both hands.
So, if you're scanning eBay at work, you'll likely only look suspicious. But, if you lean into it and use ⌘+⇥ (command+tab) PLUS ⌘+h in succession, you might actually look like you're doing work.
But, in the event you're asked to bring your browser back to the forefront you'll be busted. It will display exactly what you were looking at when you hid it.
You can imagine how I know this :-)
Typically, an application will offer a way to both close the UI and quit the application. These are usually standardized to command ⌘+W to close the UI/window and command ⌘+Q to quit the application.
Some applications will still quit entirely when you use command ⌘+W, such as Preview. You can usually rely on this shortcut to close the window without quitting, however.
I should also point out that the red button in the top left does not "quit" the application as you mentioned in the question body. It will close the window (just like command ⌘+W).
Edit: In recent versions of macOS, with the advent of tabs, the behavior is slightly different:
| Keyboard | Effect |
|---|---|
| command ⌘+W | Closes the Tab |
| command ⌘+shift+W | Closes the Window |
I am so tired of closing apps and windows just to find that they're just minimized and still have that little dot on the bar indicating that they are running. Theres a red close button and a yellow minimize button-- If I hit the close button, its because I want it gone, I'm done with it. I DONT UNDERSTAND why it functions this way.