Minimise all Windows in OS X

Like many Mac users I’ve spent many years using Windows and have a significant familiarity with the working practices and keyboard shortcuts of that OS.  One of the actions I commonly use in Windows is to minimise all windows.  It may not necessarily be “the Mac way”, but I still find myself wanting to do this and have spent some time trying to track down a keyboard shortcut that will let me do this.

When you mention this action many experienced Mac users will immediately refer you to Expose.  Using Expose will in fact display the desktop, but if you then select an application from the dock all of the application windows will come back into view with the app you selected coming to the foreground.  This isn’t quite the same.  Whilst I do use Expose, I do find that on occasion I find some of the other application windows floating in the background a little distracting - particularly web pages with ads on them.

Apple’s own Mac OS X keyboard shortcuts page lists a couple of interesting shortcuts.

  • Option-Command-H Hide the windows of all other running application.
  • Option-Command-M Minimise all windows of the active application to the dock

In combination these will effectively clear all of the windows of all applications form the screen and when an application is then selected from the dock only that application is brought up onto the screen.  Ideally I would have liked to have hidden the active application, but when the other applications have been hidden this option is disabled in an application.  So doing this will pop one or more windows into the dock.

So this is a double key combination to minimise or hide all windows.

We can however go one step further with the help of Automator and AppleScript.  By creating a service we can action these two key presses using a little piece of AppleScript and assigning the service a keyboard shortcut.

One thing I discovered whilst testing this was that sometimes when the key presses were sent automatically, the currently active application didn’t always seem to respond to the minimise command.  When physically pressing the keys it didn’t seem to be a problem, but to rectify this I added an extra bit of code to activate Finder as this will always be running and it always seems to respond appropriately.  So whilst all of the other applications will be hidden, any Finder windows will be minimised to the dock.  So the AppleScript to put into Automator for the service is as follows.

on run
    tell application "Finder" to activate
    
    tell application "System Events"
        keystroke "h" using {command down, option down}
        keystroke "m" using {command down, option down}
    end tell
end run
Author: Stephen Millard
Tags: | applescript | mac |

Buy me a coffeeBuy me a coffee



Related posts that you may also like to read