Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Possible Duplicate:
Launch an OS X app with a keyboard shortcut

Is it possible to define a global hotkey to show/hide a specific app in OS X?

For example, I want to be able to show/hide Safari with Cmd+Space.

share|improve this question

marked as duplicate by TFM, Ƭᴇcʜιᴇ007, 8088, ChrisF, Synetech Nov 12 '12 at 4:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Related to Launch an OS X app with a keyboard shortcut - Super User. I edited my answer to that question to include third party apps that support show-or-hide style triggers. I also added an AppleScript for showing or hiding an app. –  ؘؘؘ Sep 25 '11 at 13:58

3 Answers 3

up vote 2 down vote accepted

Open Automator, select to create a Service, configure to have it receive no input in any application.

From the library, double-click Utilities » Run AppleScript and enter the following into the large text area:

on run {input, parameters}

    tell application "System Events"
        set names to name of application processes
        if names contains "Safari" then
            tell application process "Safari"
                if visible then
                    set visible to false
                else
                    # use the following to simply have it reappear:
                    set visible to true
                    # use the following to focus Safari:
                    tell application "Safari" to activate
                end if
            end tell
        else
            display dialog "Safari is not running"
        end if
    end tell

    return input
end run

Save under any name. Assign a keyboard shortcut in System Preferences » Keyboard » Keyboard Shortcuts » Services. Remember to disable the Spotlight shortcut Cmd-Space.

share|improve this answer
2  
Instead of display dialog, you could alternatively tell application "Safari" to activate to launch it if it's not running. –  Daniel Beck Sep 25 '11 at 19:52

Save in AppleScript Editor and Assign a shortcut to running a script in OS X

tell application (path to frontmost application as text)
    if name is "TextEdit" then
        set bid to id
        tell application "System Events" to tell (process 1 where bundle identifier is bid)
            set visible to false
        end tell
    else
        tell application "TextEdit"
            reopen
            activate
        end tell
    end if
end tell
  • If the targeted application is currently frontmost, hide it
  • Otherwise activate it
share|improve this answer
    
The behavior of this script is as follows: If TextEdit is the frontmost application, it will be hidden, otherwise it will be brought to the front. So this script will not hide the application if it's visible but not frontmost, instead bringing it to front. –  Daniel Beck Oct 2 '11 at 7:28
    
Clever behavior. I was just missing the explanation how the shortcut behaves in your post — I think this'd be helpful. –  Daniel Beck Oct 2 '11 at 7:55
    
Thank you! I have marked Daniel's answer as he was the first. –  Roman Dolgiy Nov 25 '11 at 7:48

CMD+W will hide windows. This works globally. However To get back to them you need to be clicking on the dock icons. In a browser it will however close the tab.

share|improve this answer
    
No. Cmd + W closes windows. –  daviesgeek Sep 25 '11 at 16:33
    
Additionally, the user asks about applications, not windows. On OS X, there's very much a difference. –  Daniel Beck Sep 25 '11 at 18:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.