[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] AppleEvents Tips



Greetings-

About a week ago, I sent a message to the list concerning AppleEvents
programming. Since then, I've managed to solve the problems I asked for
help with. I'd like to share what I've learned, for the benefit of others
who might encounter the same difficulties.

The method I've been using is to create an AppleScript that does what I
want, capture the AppleEvents using the AE Capture control panel, then
construct a MacPerl script to produce the same AppleEvents.

This approach works reasonably well, but there are some things to be aware of.

First, I found that there are often many ways to script the same result. It
is a good idea to experiment with AppleScript first, to zero in on best
approach, before spending any time in MacPerl.

For instance, this snippet (which came from a sample script supplied by the
developer) adds a new category to the category table of a database:

 tell table 2 of first database
     set newCategoryID to (make row at beginning with properties {name:str,
parent:id})
 end tell

This script does the same thing:

 make new category at beginning of first database with data str

The second approach allowed me to add categories within categories, and
avoided dealing with record id's altogether. My MacPerl programming was
greatly simplified.

Second, be aware that you must manually control the conversion of
parameters into the correct type required by the application. For instance
these two parameter strings produce the same exact results within AE
Capture,

 obj {form:indx, want:type(ctbl), seld:2, .....

 obj {form:indx, want:type(ctbl), seld:long(2), .....

The application required a long parameter, and the AE would not work until
the 'long( )' type specifier was added to the parameter string.

You can find out what type is required by using David Schooley's
aete.converter. For example:

 @PROPERTY "id", 'ID  ', 'long', "The unique ID of this row", SINGLE,
NOENUM, RDONLY

Third, you should be aware that the AE capability built into MacPerl is
derived from AEGizmos. AEGizmos simplifies AE programming tremendously. It
is a good idea to get AEGizmos, and study the documentation, and the source
code. You can get AEGizmos at:

http://www.mooseyard.com/Jens/Software/

There are some limitations with AEGizmos, in particular, AEBuild doesn't
support meta-parameters (or attributes).These are the objects that begin
with an ampersand, for instance:

 .... kocl:type(crow), &subj:obj {form:indx ....

In my experience (which is very limited) I have been able to get my scripts
to work without needing attributes. But there may be instances where this
is a show stopper. I believe that attributes can be created using the
AEStream approach (see Mathias' 'Perl Anarchist's Cookbook'), so it might
be advisable to build any higher level scripting modules (such as Chris
Nandor's AEGlue) using AEStream.

Another concern about AEGizmos is that the source code has become outdated,
and Apple no longer supports it. AEGizmos was written by Jens Alfke, and it
would be great if we could persuade him to polish up his code for use in
MacPerl.

Scripting is one of the Mac's great strengths, and if AE programming can be
simplified, I expect there will be many new MacPerl users. Chris Nandor's
AEGlue module will be a significant accomplishment. Let's give him
encouragement and support to carry on that work.

-Bill

==========

One measure of a nation's character is the difference between what's legal
and what's right.




***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch