在AppleScript的,我怎么能找出是否一个菜单项选择/注重? [英] In Applescript, how can I find out if a menu item is selected/focused?

查看:199
本文介绍了在AppleScript的,我怎么能找出是否一个菜单项选择/注重?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对OS X 10.5的脚本,专注的搜索框在任何应用程序的帮助菜单。我有一个组合键,就像聚光灯下,我想它,当我运行该脚本切换。所以,我想检测是否在搜索框中早已开始关注打字,如果是这样,类型,而不是单击帮助菜单Esc键。

I have a script for OS X 10.5 that focuses the Search box in the Help menu of any application. I have it on a key combination and, much like Spotlight, I want it to toggle when I run the script. So, I want to detect if the search box is already focused for typing, and if so, type Esc instead of clicking the Help menu.

下面是脚本,因为它代表现在:

Here is the script as it stands now:

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

...但我得到这个错误:

... but I get this error:

无法得到关注的。{菜单1菜单栏项目申请过程中脚本编辑器应用程序系统事件的菜单栏1帮助菜单中的帮助的}

Can’t get focused of {menu item 1 of menu "Help" of menu bar item "Help" of menu bar 1 of application process "Script Editor" of application "System Events"}.

那么,有没有办法,我可以让我的脚本检测搜索框是否早已开始关注?

So is there a way I can get my script to detect whether the search box is already focused?


我解决我的问题,通过围绕它的工作。我仍然不知道如何,如果菜单项选择,虽然要检查,所以我会离开这个话题打开。

I solved my problem by working around it. I still don't know how to check if a menu item is selected though, so I will leave this topic open.

推荐答案

使用/开发/应用/工具/辅助工具/辅助Inspector.app您可以使用内置辅助系统来看待下UI元素的性质鼠标。需要特别注意的CMD-F7的行动,以一个元素和刷新按钮锁定对焦。可悲的是元素和属性名称不直接匹配那些在脚本套件,但你可以看一下字典系统事件或通常猜测正确的术语。

Using /Developer/Applications/Utilities/Accessibility Tools/Accessibility Inspector.app you can use the built-in accessibility system to look at properties of the UI element under the mouse. Take special note of the cmd-F7 action to lock focus on an element and the Refresh button. Sadly the element and property names don't directly match those in the script suite, but you can look at the dictionary for System Events or usually guess the right terminology.

使用这个你可以决定两件事情。首先,关注属性是不是在菜单项,而是有一个文本字段菜单项中的那就是专注。二,菜单项有一个属性。

Using this you can determine two things. First, the focused property isn't on the menu item, but rather there is a text field within the menu item that is focused. Second, the menu item has a selected property.

有了这个,我想出了:

tell application "System Events"
    tell (first process whose frontmost is true)
    	set helpMenuItem to menu bar item "Help" of menu bar 1

    	-- Use reference form to avoid building intermediate object specifiers, which Accessibility apparently isn't good at resolving after the fact.
    	set searchBox to a reference to menu item 1 of menu of helpMenuItem
    	set searchField to a reference to text field 1 of searchBox

    	if searchField's focused is true then
    		key code 53 -- type esc
    	else
    		click helpMenuItem
    	end if
    end tell
end tell

虽然这仍然无法正常工作。关键事件不会开火,据我所知,这样的东西可能还是hinky与文本字段中的关注属性。

总之,你的点击再解决方案似乎更容易。

Anyway, your click again solution seems much easier.

这篇关于在AppleScript的,我怎么能找出是否一个菜单项选择/注重?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆