Scripting the Non-scriptable
Page 3

Targeting Interface Elements Using GUI Scripting

In order to write AppleScript code that targets a user interface element in an application, you must determine the exact location of the element with which you want to interact. Interface elements must be targeted very specifically. For example, suppose you want to click a button in an application's window. Since there are multiple applications on your machine, each that potentially possesses multiple windows containing multiple buttons, you must specify the exact application, window, and button that should be clicked. The following example code demonstrates how this is done.

tell application "System Events"

     tell process "SomeProcess"

          click button "SomeButton" of window "SomeWindow"

     end tell

end tell

The names of interface elements can sometimes be difficult to determine. In addition, some interface elements are not named and must be targeted in another manner, such as by position. To assist in determining the proper locations of interface elements, Apple provides an application called Accessibility Inspector. Please note that this application is not installed with Mac OS X by default. It is included with the Mac OS X developer tools, which comes free with Mac OS X. After installing the developer tools, you will find accessibility inspector in the developer > applications > utilities > assessibility tools folder on your machine (see figure 3).

X-Ray Magazine v5n2 Sripting the Non-Scriptable Figure 3

Figure 3 The Accessibility Inspector application.

When launched, Accessibility Inspector will follow your mouse and display in a palette window the hierarchy of the interface element currently beneath the cursor. For example, figure 4 displays the hierarchy of the save button in QuarkXPress' export as PDF window.

X-Ray Magazine v5n2 Sripting the Non-Scriptable Figure 4

Figure 4 Browsing an interface element's hierarchy.

1 | 2 | 3 | 4 | PDF Version

X-Ray Magazine
X-Ray Magazine Logo
If you enjoy our articles, click here to subscribe.
AddThis Social Bookmark Button
 
Free JavaScripts provided by The JavaScript Source

 

Xdata QuarkXPress XTensions PitStop Professional Preflight Acrobat PDF

Creative Public
data2date
PDF Conference: April 30 - May 1 2008
AGI Training: Dreamweaver