GUI Scripting & the Finder under Panther
GUI Scripting & the Finder under Panther
- Subject: GUI Scripting & the Finder under Panther
- From: Bill Cheeseman <email@hidden>
- Date: Sun, 26 Oct 2003 20:27:29 -0500
This is the second in a series of tips about GUI Scripting in Panther. Some
of what I have to say here may repeat material in Apple's documentation,
which I haven't yet had time to study.
The Finder in Panther has some new terminology for GUI Scripting, which does
not appear in the System Events AppleScript dictionary where most GUI
Scripting terminology appears. Because GUI Scripting is, by definition,
separate and apart from a scriptable application's normal AppleScript
support, the Panther Finder's GUI Scripting terminology may not be
replicated in the Finder's normal AppleScript dictionary.
The first new GUI Scripting term in the Panther Finder is, technically
speaking, AXFinderItem. It represents any of the icons in a Finder window's
toolbar, its new sidebar, or the main part of the window. Its GUI Scripting
description is "Finder item", but this term can't be used when writing
scripts. Instead, you have to refer to this new UI element as, well, "UI
element". Thus, the following script works (if it is enclosed in the
standard nested GUI Scripting tell blocks addressed to 'application "System
Events"' and 'process "Finder"'):
get name of UI element "Network" of group 1 of split group 1 of window 1
The second new GUI Scripting term in the Finder is "AXOpenAction". You can
use the new GUI Scripting command "perform" and the new term "action" to
open an AXFinderItem, like so:
perform action "AXOpenAction" of UI element "Network" ... etc., as above.
The third new GUI Scripting term is "AXFinderIsContainer". This is a
Boolean, which, when used with the new term "attribute," tells you whether
the AXFinderItem is or is not a folder or other container, like so:
get value of attribute "AXFinderIsContainer" of UI element "Network" ...
These same constructs can be used to perform any GUI Scripting action or to
get the value of any GUI Scripting attribute of any application. To get a
list of all the names that you can use with "action" and "attribute", you
can use these scripts (again in the proper nested tell blocks):
get every action of ...
get every attribute of ...
The list of usable actions and attributes may vary depending on the
particular UI element you use them with. A robust script will check whether
the action or attribute is supported by the targeted UI element before
performing the action or getting the value of the attribute. Even then, many
applications (especially Cocoa applications) may appear to implement an
action or attribute when they really don't, so a robust script will also be
prepared to handle the case where the action is not performed or the
attribute has no value.
For most UI elements recognized by the System Events application, you don't
have to do this. You can instead get the attributes or perform the actions
directly by using the action's or attribute's System Events name, such as
'click button 1 of window 1' or 'get size of button 1 of window 1'. The new
perform action "myAction"' and 'get value of attribute "myAttribute"' forms
are more general, and they are required when you want to use actions and
attributes of other applications, such as the Panther Finder, that implement
their own accessibility features outside of the System Events application.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.