macos - 如何检查应用程序是否通过 MAC OS 中的 Automator 打开?

标签 macos applescript toggle automator

我正在尝试检查应用程序是否通过 AppleScript 打开

这是下面的代码:

on run {input, parameters}

quit application "KeyboardViewer"


return input
end run

但是我希望它首先检查 KeyboardViewer 是否打开,如果打开则退出应用程序,如果没有则启动它。在某种程度上,代码应该切换应用程序。

我不熟悉 AppleScript 的编码(这里是初学者),所以我希望能提供一些见解。

谢谢

编辑

我一直在尝试使用它,这似乎有效,有没有更有效的方法?我想看看您的意见

on run {input, parameters}

    if application "KeyboardViewer" is running then

        quit application "KeyboardViewer"

    else
        activate application "KeyboardViewer"

    end if

    return input
  end run

使用此脚本时会有一小段(小于 1 秒)延迟。有没有办法让它更快?

最佳答案

这似乎有效:

on run {input, parameters}

    if application "KeyboardViewer" is running then

        quit application "KeyboardViewer"

    else
        activate application "KeyboardViewer"

    end if

    return input
  end run

我了解到,if application "APPLICATION NAME"is running 检查应用程序是否打开。

关于macos - 如何检查应用程序是否通过 MAC OS 中的 Automator 打开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11863316/

相关文章:

macos - 使用 npm 1.3.11 安装 phonegap 创建密码 : directory path on Mac OSX

C++ 行在循环外重复 8 次

python - 用 Python 编写的程序可以用 AppleScripted 编写吗?

javascript - 检测 Bootstrap 下拉菜单选项的正确方法是什么?

javascript - *NgFor 切换显示/隐藏单个元素

ruby - 新安装后,SQLite3 旧版本仍然存在 (OS X)

对使用 libcurl 下载的文件所做的更改不会生效

swift - 在 Mac 上运行脚本提示 Error?

objective-c - 在我的可编写脚本的应用程序中为 "make new"提供我自己的对象

jQuery 在点击其他地方时切换隐藏