2008-09-16 17 views
5

OS X 10.5用のスクリプトがあります。このスクリプトは、どのアプリケーションのヘルプメニューにも検索ボックスを表示します。私はキーの組み合わせでそれを持っており、Spotlightと同じように、スクリプトを実行するときに切り替えるようにしたい。したがって、検索ボックスがすでに入力に集中しているかどうかを検出したい場合は、ヘルプメニューをクリックする代わりに「Esc」と入力します。AppleScriptでは、メニュー項目が選択/フォーカスされているかどうかをどのように調べることができますか?

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 

...しかし、私はこのエラーを取得:

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"}.

検索ボックスに既に焦点が当てられているかどうかを検出するスクリプトを取得する方法はありますか?


私はworking around itで問題を解決しました。私はメニュー項目が選択されているかどうかをチェックする方法はまだ分からないので、このトピックを開いたままにします。

答えて

2

/Developer/Applications/Utilities/Accessibility Tools/Accessibility Inspector.appを使用すると、組み込みのアクセシビリティシステムを使用して、マウスの下のUI要素のプロパティを表示できます。 cmd-F7アクションに特に注意して、要素とRefreshボタンにフォーカスをロックしてください。悲しいことに、要素とプロパティの名前はスクリプトスイートの名前と直接一致しませんが、システムイベントの辞書を見たり、通常正しい用語を推測したりすることができます。

これを使用すると、2つのことを判断できます。最初に、focusedプロパティはmenu itemにはなく、の中にフォーカスされているtext fieldがあります。次に、メニュー項目にはselectedというプロパティがあります。これにより

、私が思い付いた:これはまだ動作しませんが

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 

。キーイベントは私が知る限り発射していないので、テキストフィールドのプロパティを使用すると何かがヒンキーかもしれません。

とにかく、あなたのclickソリューションははるかに簡単です。

+0

'もしsearchFieldのフォーカスが真であれば' ..本当にリンゴのスクリプト構文ですか?アポストロフィを追加しますか? – abbood

4

組み込みキーのショートカットCmd-?Cmd-Shift-/)はすでにこのように動作しています。重要なフォーカスをヘルプメニューの検索フィールドに移動します(まだフォーカスがない場合)。そうでない場合はメニューを閉じます。

1

Illustratorでファイルを処理するには、この作業を自分で行う必要があります。

tell application "Adobe Illustrator" 
activate 
tell application "System Events" 
    tell process "Illustrator" 
     set frontmost to true 
     set activeMenuItem to enabled of menu item "Unlock All" of menu "Object" of menu bar item "Object" of menu bar 1 
     if activeMenuItem is true then 
      tell me to beep 3 
     else 
      tell me to beep 2 
     end if 
    end tell 
end tell 
end tell 

完了:ここ

は私が思いついたものです。

これは問題なく動作し、ファイルの反復処理に使用できます。おそらく私は将来の自動化でこれを何度もやらなければならないでしょう。

幸運を祈る!

2

属性AXMenuItemMarkCharを使用する必要があります。

例:メニュー項目がチェックされている場合

tell application "System Events" 
    tell process "Cisco Jabber" 
     set X to (value of attribute "AXMenuItemMarkChar" of menu item "Available" of menu "Status" of menu item "Status" of menu "File" of menu bar item "File" of menu bar 1) is "✓" -- check if Status is "Availible"  
    end tell 
end tell 

、戻り値はで、それ以外の場合はmissing valueです。

注:このテストは、メニューが検査されているアプリケーションが現在の最前面である場合にのみ機能します。

関連する問題