AppleScript的:在通过GUI脚本点击菜单栏项目 [英] Applescript: on clicking Menu Bar item via gui script

查看:2563
本文介绍了AppleScript的:在通过GUI脚本点击菜单栏项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让名为F.lux的应用程序,如下面的截图显示,点击菜单项关闭一小时的AppleScript:

元素路径在下面的截图所示:

下面是我的code迄今:

 告诉应用程序系统事件
    告诉进程流量
        单击(菜单栏2菜单栏第1项)
        点击菜单项关闭一小时的菜单栏项目1菜单1
        菜单栏2
    告诉结束
告诉结束

一切编译罚款,但我不断收到的时候我尝试运行下面的脚本错误消息:


  

    

错误系统事件得到了一个错误:无法获取的过程\\菜单栏2菜单栏项目1菜单1流量\\无效的指数。从工艺流量

的菜单栏2菜单栏项目1菜单1号-1719
  

有人可以找出我要去哪里错了呢?


解决方案

这为我工作,但有大约5秒第一次点击命令后的延迟。

 告诉应用程序系统事件告诉进程流量
    告诉菜单栏2菜单栏项目1
        点击
        点击菜单项关闭一小时菜单1
    告诉结束
告诉结束

一个解决方法是使用忽略了应用程序的响应并终止系统事件的点击命令后:

 忽略应用程序的响应
    告诉应用程序系统事件告诉进程流量
        单击菜单栏2菜单栏项目1
    告诉结束
忽略结束
做shell脚本killall系统\\\\事件
延迟0.1
告诉应用程序系统事件告诉进程流量
    告诉菜单栏2菜单栏项目1
        点击菜单项关闭一小时菜单1
    告诉结束
告诉结束

I'm trying to make an applescript for an application called F.lux that clicks the menu item "Disable for an Hour" as indicated in the screenshot below:

The element path is indicated in the screenshot below:

Here is my code thus far:

tell application "System Events"
    tell process "Flux"
        click (menu bar item 1 of menu bar 2)
        click menu item "Disable for an hour" of menu 1 of menu bar item 1 of        
        menu bar 2
    end tell    
end tell

Everything compiles fine, however I keep getting the error message below when I attempt to run the script:

error "System Events got an error: Can’t get menu 1 of menu bar item 1 of menu bar 2 of process \"Flux\". Invalid index." number -1719 from menu 1 of menu bar item 1 of menu bar 2 of process "Flux"

Can someone pinpoint where I'm going wrong with this?

解决方案

This worked for me, but there is a delay of about 5 seconds after the first click command.

tell application "System Events" to tell process "Flux"
    tell menu bar item 1 of menu bar 2
        click
        click menu item "Disable for an hour" of menu 1
    end tell
end tell

One workaround is to use ignoring application responses and terminate System Events after the click command:

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
        click menu item "Disable for an hour" of menu 1
    end tell
end tell

这篇关于AppleScript的:在通过GUI脚本点击菜单栏项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆