1

这是上一个问题 Applescript: on click Menu Bar item via gui script的扩展

在 f.lux 菜单栏下方突出显示的菜单项上,如果单击它,将出现一个复选标记,表示“禁用一小时”功能已启用。我想要做的是为 f.lux 编写一个 GUI AppleScript,用户可以决定通过在 Alfred 中键入关键字后跟 1 或 0 来切换复选标记,其中 1 用于启用“禁用一小时" 和 0,用于保持它不被选中。

这是 f.lux 菜单栏的屏幕截图

元素检查器的屏幕截图,提供有关

但是,我很难弄清楚要为“禁用一小时”菜单项调整什么属性以切换复选标记。这是代码,但是通过applescript编辑器编译它时出现意外的令牌错误。到目前为止,我要做的是针对上面屏幕截图中箭头指示的“菜单项标记字符”属性,但我不确定这是否是切换“禁用一小时”项的正确方法。有人可以给我建议吗?

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 回答