Global hotkey to show/hide a specific app in OS X? [duplicate]

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.


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