【问题标题】:Launch/raise application and cycle through its windows using AppleScript and keyboard shortcut使用 AppleScript 和键盘快捷键启动/启动应用程序并在其窗口中循环
【发布时间】:2017-02-17 07:24:09
【问题描述】:

如何使用 AppleScript 创建键盘快捷键:

  • 如果应用程序没有运行,请启动它。
  • 如果应用程序正在运行,则将其置于前台。
  • 如果我一直按快捷键,仅循环浏览应用程序的窗口。

例如,当我按下 Option-Y 时,它将启动终端或将其带到前台,如果我一直按 Option-Y,如果我打开了多个终端窗口,它将循环显示多个打开的终端窗口。

我已使用 Automator 作为服务成功创建了 AppleScript。我已成功将此脚本映射到键盘快捷键,方法是转到系统偏好设置、键盘、快捷方式、服务并在常规下检查并为 Automator 服务 BringTerminalToTheForeground 分配键盘快捷键。

这是启动终端的脚本:

tell application "Terminal"
    activate
end tell

我只想使用 Mac 默认附带的工具(例如 AppleScript、Automator)来执行此操作。我正在运行 El Capitan。

【问题讨论】:

    标签: applescript cycle launch automator


    【解决方案1】:

    Command-"`" 将循环浏览应用程序的窗口。

    tell application "Terminal" -- try other applications. This script might work in other cases. It happens to work with Terminal but I haven't tested it.
        activate
        set c to count of windows -- we need to know how many windows the application has so we only cycle through all of them once.
        tell application "System Events"
            repeat c times
                keystroke "`" using command down --  this is what cycles through the windows. This doesn't work in every application.
                delay 1 -- this is a 1-second delay. Change this to whatever delay you want.
            end repeat
        end tell
    end tell
    

    【讨论】:

      【解决方案2】:

      我有你想要的,但我正在使用 hammerspoonKarabiner ElementsGokuRakuJoudo(可选但强烈推荐)。

      首先,您必须使用 Hammerspoon https://github.com/fabiomcosta/keyboard/blob/73b22906b31dfc12cc834c382515e30c4450d0f5/hammerspoon/hyper.lua#L76 创建这个 lua 模块,然后在我的 karabiner.edn(使用 Goku)上定义一个使用 Hammespoon 的 cli hs 调用该函数的键映射。

      设置起来并不容易,事实上这就是为什么我正在寻找一种新的方法来实现相同的行为而无需这么多设置哈哈。 但它绝对有效。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-04
        • 1970-01-01
        相关资源
        最近更新 更多