Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript for menu items (error -1719)

Disclaimer: I've got no idea what I'm doing... I put this applescript together based on trial and error and some stuff I found on the internet


So I've been trying to put together an applescript to string together two menu commands that I use in a program called "FlySketch". This is the script:



tell application "FlySketch"
  activate
end tell
tell application "System Events"
          tell process "FlySketch"
                    tell menu bar 3
                              click menu item "Screen Snapshot Background"
                    end tell
                    tell menu bar 3
  click menu item "Copy"
                    end tell
          end tell
end tell



When I run it, I get this error:

error "System Events got an error: Can’t get menu bar 3 of process \"FlySketch\". Invalid index." number -1719 from menu bar 3 of process "FlySketch"



Can't tell what's going wrong... I emailed the developer and he didn't seem to know why it wasn't working either.


Any thoughts?

Unibody MBP, Intel iMac, Mac OS X (10.6.3), 15" Unibody MBP (2.53 GHz Core 2 Duo/4GB/512 MB 9600M GT), iMac

Posted on May 22, 2011 3:25 PM

Reply
Question marked as Best reply

Posted on May 22, 2011 4:45 PM

Try this:


tell application "FlySketch" to activate

tell application "System Events" to tell process "FlySketch"

tell menu 1 of menu bar item 4 of menu bar 1

click menu item "Screen Snapshot Background"

clickmenu item "Copy"

end tell

end tell

5 replies

May 22, 2011 4:54 PM in response to redsteven1

Pierre L. beat me to it, but each menu bar (normally just the one) has menu bar items, each menu bar item has a menu, each menu has menu items, and each menu item can be menus that have menu items, etc. If you have the Developer Tools installed, there is an Accessibility Inspector application in the /Developer/Applications/Utilities/Accessibility Tools folder that you can use to see the hierarchy of the GUI items.

May 22, 2011 5:46 PM in response to redsteven1

For some reason I find it easier to work backwards from the UI element; so the following also works:


tell application "FlySketch" to activate

tell application "System Events"

tell process "FlySketch"

click menu item "Screen Snapshot Background" of menu 1 of menu bar item "Edit" of menu bar 1

clickmenu item "Copy" of menu 1 of menu bar item "Edit" of menu bar 1

end tell

end tell




There is also a nice GUI tool, UI Browser found at http://pfiddlesoft.com/uibrowser/ It's $55 but if you do a lot of GUI scripting it's might be worth it. You can download a free trial.

May 22, 2011 6:57 PM in response to redsteven1

If you need only the menu commands "Screen Snapshot Background" and "Copy" and don't wish to enable access for assistive devices, you might also use the following code:


tell application "FlySketch.app" to activate

tell application "System Events"

keystroke "k" using {command down}

keystroke "c" using {command down}

end tell


You might also have a look at the following Web page:

http://www.macosxautomation.com/applescript/uiscripting/index.html

Applescript for menu items (error -1719)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.