我正在尝试检查应用程序是否通过 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/