2013-05-12 39 views
1

这是前一个问题 Applescript: on clicking Menu Bar item via gui script菜单项旁边的AppleScript反复复选标记

在下面的f.lux菜单栏的高亮显示的菜单项目的延伸,如果你点击它,会出现一个对号,表明“禁用一小时”功能已启用。我想要做的是为f.lux编写一个GUI AppleScript,用户可以通过在Alfred中键入一个关键字来决定切换复选标记,后面是1或0,其中1用于启用“禁用一小时“和0,用来保持不受检查。

这是菜单栏的f.lux

screen shot of the element inspector providing info on the "Disable for an hour" element and its attributes

但是我有一个很难搞清楚什么属性的调整“禁用一小时”菜单项中的屏幕截图为了切换复选标记。这里是代码,但是当通过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 

回答

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 
+2

这完美地工作,我想给予好评你,但我需要代表。 – 2013-05-12 07:49:43