help with GUI scripting examples/tutorial

greetings - I’m somewhat new to applescript and I’m trying to figure out how all this gui scripting works.
The following code performs as I expect. It opens a window:


tell application "System Events"
	tell process "Bookends 8"
		tell menu bar 1
			tell menu bar item "File"
				click
				tell menu 1
					click menu item 5
				end tell
			end tell
		end tell
	end tell
end tell

However, the following code throws an error:


tell application "System Events"
	tell process "Bookends 8"
		tell menu bar 1
			tell menu bar item "File"
				tell menu 1
					click menu item "Import References..."
				end tell
			end tell
		end tell
	end tell
end tell

But, according to Apple’s GUI scripting tutorial, that second block of code should work.
UI Element Inspector tell me:

<AXApplication: “Bookends 8”>

<AXMenuBarItem: “File”>

<AXMenuItem: “Import References.”>

Obviously there’s something I’m not getting here. Can anyone tell me what’s going on and/or point me to a more detailed tutorial on GUI scripting? Many thanks!
Mike

Browser: Safari 416.13
Operating System: Mac OS X (10.4)

Hi. I do not have the app “Bookends” but I checked your logic using Quark XPress. System events should work the same whatever the app. I have two thoughts:

  1. I usually activate the application and then tell system events to do something. Not sure if this makes a difference but you have system events telling your application. You might want to put the app “tell” on the outside.

  2. You can simplify all those embedded tells into one line. Try this, and then try substituting “Import References…” for “5”:


tell application "Bookends 8"
	--activate   --Don't know if you want this or not.
	tell application "System Events"
		click menu item 5 of menu "File" of menu bar item "File" of menu bar 1 of process "Bookends 8"
	end tell
end tell

Model: Mac G5
Browser: Safari 312.3.1
Operating System: Mac OS X (10.3.9)

Have you tried using an ellipsis (“.” [press Option+Semicolon]) instead of three periods?

Yup, that seems to work. In this application I have to click the menu bar item “File” before click menu item “Import References.” However, in TextEdit, this is not the case, so it must depend on how the application is written.

Also, I discovered that Import References. Does indeed have an ellipsis on the end and not three periods!

Thanks for all your help!

I noticed today while trying to UI script Quark, a couple of things. First, the order in which you do things really matters to Xpress. Second, download that UI Browser thing. It’s really helpful. It costs money but there’s a 30 day trial. And lastly, if you want it to do anything whil a document is open, the document can’t be minimized to the dock.