【问题标题】:AppleScript toggling checkmarks beside menu itemsAppleScript 切换菜单项旁边的复选标记
【发布时间】:2013-05-12 05:40:07
【问题描述】:

这是对上一个问题的扩展 Applescript: on clicking 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

【问题讨论】:

    标签: macos applescript


    【解决方案1】:

    这似乎有效:

    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
    

    【讨论】:

    • 这工作完美无缺,我想投票给你,但我需要代表。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-18
    • 1970-01-01
    • 1970-01-01
    • 2016-09-24
    • 1970-01-01
    • 1970-01-01
    • 2014-08-16
    相关资源
    最近更新 更多