【发布时间】:2010-09-09 07:14:21
【问题描述】:
我有一个用于 OS X 10.5 的脚本,该脚本将搜索框集中在任何应用程序的帮助菜单中。我把它放在一个组合键上,就像 Spotlight 一样,我希望它在我运行脚本时切换。所以,我想检测搜索框是否已经专注于输入,如果是,请输入 Esc 而不是单击帮助菜单。
这是现在的脚本:
tell application "System Events"
tell (first process whose frontmost is true)
set helpMenuItem to menu bar item "Help" of menu bar 1
click helpMenuItem
end tell
end tell
我正在考虑这样的事情:
tell application "System Events"
tell (first process whose frontmost is true)
set helpMenuItem to menu bar item "Help" of menu bar 1
set searchBox to menu item 1 of menu of helpMenuItem
if (searchBox's focused) = true then
key code 53 -- type esc
else
click helpMenuItem
end if
end tell
end tell
...但我收到此错误:
无法获得{应用程序“系统事件”的应用程序进程“脚本编辑器”的菜单栏项“帮助”的菜单“帮助”的菜单项 1} 的焦点。
那么有没有办法让我的脚本检测搜索框是否已经聚焦?
我通过working around it 解决了我的问题。我仍然不知道如何检查菜单项是否被选中,所以我将保持这个话题打开。
【问题讨论】:
标签: macos focus applescript menu