Applescript to click on a specific icon in the Mac Menu Bar
Asked Answered
R

1

8

Sometimes I use PdaNet to tether using my iPhone. The desktop client for OSX is not as rich as the one for 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.

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 ?

Here is what the 'PdaNetMac' application's menu bar icon looks like:

enter image description here

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:

  1. Click menu item on Mac OSX Lion using AppleScript
  2. Applescript: on clicking Menu Bar item via gui script
  3. Accessing dock icon right-click menu items with 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.

Thanks!!

Roentgen answered 15/12, 2013 at 14:41 Comment(0)
C
11

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).

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 !)

Catercorner answered 15/12, 2013 at 14:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.