这是前一个问题Applescript的扩展 :通过gui脚本单击菜单栏项
在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
Run Code Online (Sandbox Code Playgroud)
这似乎有效:
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1292 次 |
| 最近记录: |