Applescript: Unhide / Restore All Windows

I got tried of accidentally hitting the CMD-H key and having a window disappear. So I wrote this little script and then assigned it to CMD-SHIFT-H to restore (unhide, unminimize) all hidden or minimized windows. Works on OS X 10.6, 10.7, 10.8, and 10.9 Snow Leopard, Lion, Mountain Lion, and Mavericks. Feel free to post improvements in the comments. I also think it would be cool to figure out the last window that was hidden, something like tell previous application and just restore that one. But this works for now.

tell application "System Events"
    repeat with theApplication in application processes
        if visible of theApplication is not true then
            set visible of theApplication to true
        end if
    end repeat
end tell

You can also do this with an Application like Terminal.app:

tell application "System Events"
    repeat with theApplication in application "Terminal"
        if visible of theApplication is not true then
            set visible of theApplication to true
        end if
    end repeat
end tell

Sometimes if you have “Minimized” instead of “Hidden” an application, it still won’t come back into the foreground when using the previous methods, so you can also try something like this:

do shell script "open '/Applications/Utilities/Terminal.app'"

This works by telling the application to “open” again which should also bring it to the front.

Related Posts:

This entry was posted in Mac and tagged , . Bookmark the permalink.

One Response to Applescript: Unhide / Restore All Windows

Leave a Reply

Your email address will not be published. Required fields are marked *