1

これは、以前の質問 Applescript: on click Menu Bar item via gui scriptの拡張です

下の f.lux メニュー バーの強調表示されたメニュー項目をクリックすると、[1 時間無効にする] 機能が有効になっていることを示すチェックマークが表示されます。私がやろうとしているのは、f.lux の GUI AppleScript を作成することです。ユーザーは、Alfred にキーワードを入力し、その後に 1 または 0 を入力してチェック マークを切り替えるかどうかを決定できます。ここで、1 は「1 時間無効にする」 " および 0 は、チェックを外しておくのに役立ちます。

これは、f.lux のメニュー バーのスクリーン ショットです。

に関する情報を提供する要素インスペクタのスクリーン ショット

ただし、チェックマークを切り替えるために「1時間無効にする」メニュー項目を調整する属性を理解するのに苦労しています。コードは次のとおりですが、applescript エディターでコンパイルすると、予期しないトークン エラーが発生します。これまでのところ、上のスクリーンショットの矢印で示されている「メニュー項目マーク文字」属性をターゲットにしようとしていますが、これが「1 時間無効にする」項目を切り替える正しいアプローチであるかどうかはわかりません。誰かアドバイスをお願いできますか?

on alfred_script(q)
    set myOption to q as integer

ignoring application responses
    tell application "System Events" to tell process "Flux"
        click menu bar item 1 of menu bar 2
    end tell
end ignoring
do shell script "killall System\\ Events"
delay 0.1
tell application "System Events" to tell process "Flux"
    tell menu bar item 1 of menu bar 2
        if myOption is 1 then
            set ✓ to value of attribute "AXMenuItemMarkChar" of menu item "Disable for an hour" of menu 1

        else if myOption is 0 then
            set nil to value of attribute "AxMenuItemMarkChar" of menu item "Disable for an hour" of menu 1

        end if

    end tell 
end tell

end alfred_script
4

1 に答える 1

5

これはうまくいくようです:

tell application "System Events" to tell process "Flux"
    tell menu bar item 1 of menu bar 2
        set v to (value of attribute "AXMenuItemMarkChar" of menu item "Disable for an hour" of menu 1) as string
        if (v = "" and myOption = 1) or (v is not equal to "" and myOption = 0) then
            click menu item "Disable for an hour" of menu 1
        else
            key code 53
        end if
    end tell
end tell
于 2013-05-12T07:35:48.720 に答える