Whenever I wake my Mac up, it shows my workspace exactly how I left it. If I closed the lid while browsing my library on iTunes, for example, it will show that screen upon waking up, after I input my password.

Is there a way to change this default behavior? Once I close the lid, when I come back and input my password, I'd like to view the desktop. The apps shouldn't be quit or anything like that, just the windows should be hidden. You know, to start fresh, uncluttered.

(Similar to what this user is asking, but upon waking up instead of a keyboard combination.)

Is it possible? Maybe with some Apple Script or command line magic?

3 Answers 3


You have two options, maybe more 😅:

  1. Automator:

    • Make an Application document
    • Add the following action:

      Library -> Utilities -> Hide All Applications

    • Save the App

    • Add it to your login items

      System Preferences -> Users & Groups -> Choose your User -> Login Items

    • Voilà!, on next login all open apps will be hidden. Note that with this option, if the automator app have a window, that window will not hide, because this action is for Hide All Other apps

    Automator Hide All Apps

    1. AppleScript: You can use this script, i found it on LiveJournal:
tell application "System Events" to set all_apps to the name of every process whose visible is true

repeat with a in all_apps
    tell application a to try
        repeat with w in (get every window)
            set miniaturized of w to true
        end repeat
    on error
        tell application "System Events" to repeat (count windows of process a) times
            keystroke "m" using command down
            delay 0.1
        end repeat
    end try
end repeat

Similarly you need to make this script runs on start of your session, maybe you could make an App with Automator but instead using "Hide All Application" Action, you add "Run AppleScript" Action.

In both options, maybe some applications will not be hidden because at the time this runs, not all windows are yet opened.

  • I had fun trying this, thanks for you answer! Unfortunately, it doesn't quite work. First because login items run only on startup, and I very rarely turn off or restart my computer. It would need to run upon waking up from a sleep state. Second because it doesn't hide all windows, it hides all other windows — meaning "except the one that has focus". Maybe there's no way... Commented Sep 11, 2015 at 23:46
  • Maybe with some modification and then you can try this
    – ybrajim
    Commented Sep 12, 2015 at 1:22

If you're willing to use a commercial utility, Keyboard Maestro (which I swear by) has a "System Wake" macro trigger and a "Hide All Applications" action which would do the trick.


Option 1: The code below can work almost perfectly to hide all apps. I got this idea from ybrajim's code.

The AppleScript repeats to do shortcut (Command + H) in every visible application, finally it will hide all the apps perfectly.

The only thing is that, to simulate keystroke, you need to give this automator Accessibility access by going to System Preferences → Security & Privacy → Privacy.

on run {input, parameters}

tell application "System Events" to set all_apps to the name of every process whose visible is true

repeat with a in all_apps
    tell application "System Events" to keystroke "h" using command down
    delay 0.1
end repeat

end run

In some occasional case, if the app redefines Command + H, this script will pause.

Option 2: I finally choose this one

on run {input, parameters}
activate application "Finder"
tell application "System Events" to keystroke "h" using {option down, command down}
delay 1
tell application "System Events" to keystroke "w" using {command down}

end run

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .