在OS X中显示/隐藏特定应用程序的全局热键?[重复]


10

可能重复:
使用键盘快捷键启动OS X应用

是否可以定义全局热键以显示/隐藏OS X中的特定应用程序?

例如,我希望能够使用Cmd+ 显示/隐藏Safari Space


相关超级用户-启动的OS X应用程序使用键盘快捷键。我对该问题的答案进行了编辑,以包含支持显示或隐藏样式触发器的第三方应用程序。我还添加了一个AppleScript用于显示或隐藏应用程序。
Lri 2011年

Answers:


7

打开Automator,选择创建服务,将其配置为在任何应用程序中接收任何输入

在库中,双击实用程序»运行AppleScript,然后在大文本区域中输入以下内容:

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

用任何名称保存。在系统偏好设置»键盘»键盘快捷方式»服务中分配键盘快捷方式。请记住禁用Spotlight快捷方式Cmd-Space


2
相反的display dialog,你可以替换tell application "Safari" to activate,如果它没有运行启动它。
丹尼尔·贝克

3

在AppleScript编辑器中保存并分配在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
  • 如果目标应用程序当前位于最前面,则将其隐藏
  • 否则激活它

该脚本的行为如下:如果TextEdit是最前面的应用程序,它将被隐藏,否则它将被放在最前面。因此,此脚本将不会隐藏应用程序(如果可见但不在最前面),而是将其置于最前面。
丹尼尔·贝克

聪明的举止。我只是缺少解释快捷方式在您的帖子中的行为的解释-我认为这会有所帮助。
丹尼尔·贝克

谢谢!我已将丹尼尔的答案标记为他的第一个答案。
Roman Dolgiy 2011年

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.