Saturday, September 24, 2022

#1 2005-12-07 08:55:05 am

mert
Member
Registered: 2005-12-07
Posts: 6

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:

Applescript:


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:

Applescript:


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”>
<AXMenuBar>
  <AXMenuBarItem: “File”>
   <AXMenu>
    <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)


Filed under: System

Offline

 

#2 2005-12-07 09:35:26 am

Matt-Boy
Member
Registered: 2005-10-21
Posts: 480

Re: help with GUI scripting examples/tutorial

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:<p>
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.<p>
2) You can simplify all those embedded tells into one line. Try this, and then try substituting "Import References..." for "5":<p>

Applescript:


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)

Last edited by Matt-Boy (2005-12-07 09:37:56 am)


Filed under: System, Bookends

Offline

 

#3 2005-12-07 10:29:13 am

Bruce Phillips
Administrator
Registered: 2004-07-16
Posts: 2649

Re: help with GUI scripting examples/tutorial

mert wrote:

Applescript:

click menu item "Import References..."


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

Offline

 

#4 2005-12-07 12:31:27 pm

mert
Member
Registered: 2005-12-07
Posts: 6

Re: help with GUI scripting examples/tutorial

Jacques wrote:

With this application ( click menu item "Import References...") or (click menu item 5 ) does not works if you don't click to the menu file before.


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!

Offline

 

#5 2005-12-17 12:57:11 am

pgaulrapp
Member
Registered: 2005-10-13
Posts: 8

Re: help with GUI scripting examples/tutorial

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.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)