ACTIVATING UI SCRIPTING

The GUI Scripting architecture is based upon the Mac OS X accessibility frameworks that provide alternative methods of querying and controlling the interfaces of the OS and applications.

By default, the accessibility frameworks are disabled. An administrative user can enable them by clicking the checkbox labeled "Enable access for assistive devices" in the Universal Access System Preference pane and entering their password in the forthcoming authentication dialog.



Once the accessibility frameworks have been activated, AppleScript can be used to query and control the user interface of most applications. Scripted actions are performed by addressing the System Events application which has a special script suite for communicating with the GUI Scripting architecture.

Checking Accessibility Status
In order for UI scripts to function, the accessibility frameworks must be active. The System Events application has a special property named UI elements enabled that returns a value of true or false depending upon the current accessibility state. Include the following sub-routine in your scripts to check for the presence of Mac OS X v.10.3 and an activated GUI Scripting architecture.

click to open script in Script Editor If you're using Mac OS X version 10.3, click this icon to automatically open the script example in the Script Editor application.

on UIscript_check()
-- get the system version
set the hexData to system attribute "sysv"
set hexString to {}
repeat 4 times
set hexString to ((hexData mod 16) as string) & hexString
set hexData to hexData div 16
end repeat
set the OS_version to the hexString as string
if the OS_version is less than "1030" then
display dialog "This script requires the installation of " & ¬
"Mac OS X 10.3 or higher." buttons {"Cancel"} ¬
default button 1 with icon 2
end if
-- check to see if assistive devices is enabled
tell application "System Events"
set UI_enabled to UI elements enabled
end tell
if UI_enabled is false then
tell application "System Preferences"
activate
set current pane to ¬
pane "com.apple.preference.universalaccess"
set the dialog_message to "This script utilizes " & ¬
"the built-in Graphic User Interface Scripting " & ¬
"architecture of Mac OS X " & ¬
"which is currently disabled." & return & return & ¬
"You can activate GUI Scripting by selecting the " & ¬
"checkbox “Enable access for assistive devices” " & ¬
"in the Universal Access preference pane."
display dialog dialog_message buttons {"Cancel"} ¬
default button 1 with icon 1
end tell
end if
end UIscript_check


Next Page
TABLE OF CONTENTS

Introduction

Activating UI Scripting - Enabling the GUI Scripting architecture

UI Element Inspector - Discovering an object's heirarchy

Example Scripts - Example scripts and routines