applescript - OSX applescript - 检查焦点应用程序是否不是finder,否则不执行命令
问题描述
我对applescript有点生疏了;试图找出当前焦点应用程序是否是finder,如果是,程序将退出。否则,它应该执行一个命令。
问题是我找不到检查当前焦点应用程序是否是finder的方法。是否在线搜索并且有示例显示如何使应用程序成为焦点,但我只想检索具有焦点的应用程序的名称;并检查脚本是否应该退出或继续。像这样的东西;虽然我没有命令检查焦点应用程序。
tell application "System Events"
# check if finder is the process on focus
if "Finder" is in focus then
display dialog ("Finder is in front")
else
display dialog ("Finder is not in front")
end if
end tell
解决方案
每个应用程序,不管它是否有一个 AppleScript 字典,都有一个frontmost
属性。
所以你可以简单地写(System Events
不需要)
if frontmost of application "Finder" then
display dialog ("Finder is in front")
else
display dialog ("Finder is not in front")
end if
推荐阅读
- java - 键绑定API。输入不知道
- java - Spring Data Jpa 为查询添加前缀
- python - 在 Django 视图中设置 cookie 的最佳方法?
- email - 在 Outlook 2013 中的移动设备或桌面上显示时事通讯电子邮件
- wordpress - CentOS7 Apache - 提供页面,但基本 url 提供内部地址并且无法访问
- c - 读取 C 中引号之间有空格的用户输入字符串并保留引号
- c# - 项目背景的复选框颜色
- ember.js - Ember:如何判断 peekAll 是否返回任何模型?
- javascript - Javascript 正则表达式 - | (OR) 运算符仅返回第一个匹配项
- r - 如何通过针对协变量等进行调整的治疗来绘制预测因子?