只有Chrome处于焦点时我才需要运行我的AppleScript

时间:2017-03-30 03:59:16

标签: google-chrome applescript

我正在使用键盘快捷键触发AppleScript。效果很好。但是,如果谷歌Chrome目前处于关注状态,我需要该脚本才能运行。我发现的所有可能相关的例子都非常复杂(至少对我而言)并没有真正做到我需要的。我可以使用简单的“if”语法吗?如果没有,最简单的解决方案是什么?这就是我所拥有的:

tell application "Google Chrome"
    delete tab (active tab index of window 1) of window 1
end tell

tell application "Mail"
    activate
end tell

1 个答案:

答案 0 :(得分:0)

每个应用都有frontmost属性

if application "Google Chrome" is frontmost then
    tell application "Google Chrome" to delete tab (active tab index of window 1) of window 1
    activate application "Mail"
end if