简体   繁体   English

Applescript单击Mac菜单栏中的特定图标

[英]Applescript to click on a specific icon in the Mac Menu Bar

Sometimes I use PdaNet to tether using my iPhone. 有时我使用PdaNet使用我的iPhone系绳。 The desktop client for OSX is not as rich as the one for windows. OSX的桌面客户端不像Windows的桌面客户端那么丰富。 One of the chief differences is, that the OSX does not allow to automatically connect to iPhone as soon as the latter is plugged in. 其中一个主要区别是OSX不允许在插入后立即自动连接到iPhone。

Would you know of a way using Applescript to click on the PdaNet icon on the Menu Bar and then select and click the 'Connect' option on it ? 您是否知道使用Applescript单击菜单栏上的PdaNet图标,然后选择并单击其上的“连接”选项?

Here is what the 'PdaNetMac' application's menu bar icon looks like: 以下是'PdaNetMac'应用程序的菜单栏图标:

在此输入图像描述

I have looked at the following questions but am an applescript newbie and am not sure how to search for PdaNet's icon on the menu bar: 我看了下面的问题,但我是一个苹果新手,不知道如何在菜单栏上搜索PdaNet的图标:

  1. Click menu item on Mac OSX Lion using AppleScript 使用AppleScript单击Mac OSX Lion上的菜单项
  2. Applescript: on clicking Menu Bar item via gui script Applescript:通过gui脚本单击菜单栏项
  3. Accessing dock icon right-click menu items with AppleScript 使用AppleScript访问停靠栏图标右键菜单项

I have confirmed that 'Enable Access for assistive devices' is enabled. 我已确认已启用“为辅助设备启用访问”。

Based on the second question above, Here is my current attempt at doing this: 根据上面的第二个问题,这是我目前的尝试:

ignoring application responses
    tell application "System Events" to tell process "PdaNet"
        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 "PdaNet"
    tell menu bar item 1 of menu bar 2
        click menu item "Connect" of menu 1
    end tell
end tell

Interestingly, the above script works for me fine when I change PdaNet to Flux . 有趣的是,当我将PdaNet更改为Flux时,上面的脚本对我PdaNet用。

Thanks!! 谢谢!!

You were very close !! 你非常接近!!

I just downloaded the PdaNet application to test this, and the only edit I had to make to your script was change PdaNet to 'PdaNetMac` ( I was thinking that this is the Process Name and so used the process name displayed in Activity Monitor). 我刚刚下载了PdaNet应用程序来测试它,我必须对你的脚本进行的唯一编辑是将PdaNet更改为'PdaNetMac`(我以为这是进程名称,因此使用了Activity Monitor中显示的进程名称)。

So this works for me: 这对我有用:

ignoring application responses
    tell application "System Events" to tell process "PdaNetMac"
        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 "PdaNetMac"
    tell menu bar item 1 of menu bar 2
        click menu item "Connect" of menu 1
    end tell
end tell

Hope this works for you too !! 希望这也适合你!

(Very useful script, btw. Cheers !) (非常有用的脚本,顺便说一句。干杯!)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM