select - Applescript - targeting a menu with numeric ID - Stack Overflow

admin2025-04-19  0

I'm a noob at Applescript, but managed to get the first half of this script to just display the menu. The image is a mouse hover to display the UI Browser result. The syntax for clicking on a menu with a long number instead of a name eluded all my searching. Perhaps a Relative Specifier could work for that specific menu item?

tell application "System Events"
tell process "Remote Desktop Scanner"
    tell menu bar 2
        click menu bar item 1
        click menu item 2 of "menu -9223372036854775808" (this bit failed)
    end tell
end tell
end tell

I'm a noob at Applescript, but managed to get the first half of this script to just display the menu. The image is a mouse hover to display the UI Browser result. The syntax for clicking on a menu with a long number instead of a name eluded all my searching. Perhaps a Relative Specifier could work for that specific menu item?

tell application "System Events"
tell process "Remote Desktop Scanner"
    tell menu bar 2
        click menu bar item 1
        click menu item 2 of "menu -9223372036854775808" (this bit failed)
    end tell
end tell
end tell

Share edited Mar 4 at 7:44 bobzIlla asked Mar 4 at 7:24 bobzIllabobzIlla 1711 silver badge6 bronze badges 9
  • -9223372036854775808 looks like a bug somewhere, it's 0x0x8000000000000000. "menu -9223372036854775808" is a string. Try click menu item 4 of menu 1. – Willeke Commented Mar 4 at 17:25
  • Thank you - it seems to hang with no click executed, Script Editor result: "missing value" – bobzIlla Commented Mar 4 at 18:31
  • 1 What happens if you run a get menus of menu bar 2? And menus of menu bar 1 for that matter? – Mockman Commented Mar 5 at 4:02
  • Try delay 0.5 to wait for the menu. – Willeke Commented Mar 5 at 4:16
  • Thanks so much, tried all 3 of these suggestions (and Mockman's one at a time), same basic result: "System Events got an error: Can’t get menu bar 1 of menu bar 2 of process \"Remote Desktop Scanner\". Invalid index." number -1719 from menu bar 1 of menu bar 2 of process "Remote Desktop Scanner" Feels like it may not be do-able the way the app was written? – bobzIlla Commented Mar 5 at 4:40
 |  Show 4 more comments

1 Answer 1

Reset to default 0

Turns out that Remote Desktop Scanner app was piggybacking on the native macOS Screen Sharing app. I guess it's useful for 'bookmarking' several server addresses, and providing the toolbar icon. I mistakenly thought I needed a third party solution to VNC to a PC running RealVNC.

Once I got over feelings of derp, I was able to achieve the proper sequence to get the desired behavior. Not sure why it took a doubling up of keystroke return and key code 36 to execute a working return key press for a pupup window, but this worked for me. Came away learning more about Applescript, thanks so much for the help.

tell application "/System/Library/CoreServices/Applications/Screen Sharing.app" to activate 
tell application "System Events"keystroke "192.168.1.130"
keystroke return
key code 36
end tell
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745057548a282493.html

最新回复(0)