[Pythonmac-SIG] make locations with aeve

has hengist.podd at virgin.net
Tue Dec 2 20:04:54 EST 2003


Donovan wrote:

>>But it fails because it doesn't have the at ... argument, i.e. if I 
>>run the applescript without the at... argument, I get the same 
>>error.  Any hints?
>
>
>I tried this with TextEdit, and had the same problem. I couldn't 
>make a new document without specifying the insertion location:

This is an <ahem> "feature" of TextEdit/Cocoa's built-in scripting 
support. Carbon applications are generally smart enough to know where 
a document object is supposed to be inserted and take care of it 
automatically. Indeed, if you try to use 'make new document at end of 
documents' in something like Tex-Edit Plus (whose scripting support 
is leagues ahead of TextEdit's), it'll complain about it. TextEdit, 
however, is stupid, so despite there being only one place a new 
document can go it insists on you specifying it anyway, and will even 
let you specifiy stupid locations such as 'end of windows' without 
bothering to complain. Rough rules of thumb: Cocoa apps are Stupid. 
Carbon apps are not quite as Stupid. Application dictionaries are 
painfully, painfully inadequate. Anticipate plenty of trial-and-error 
when figuring out how things work.

FWIW, I reckon the best place to ask for advice on scripting specific 
apps is probably be the MacScrpt mailing list: while a lot of 
discussion is AppleScript related it's not an AppleScript-specific 
list, so you might feel a bit more comfortable there than in a pure 
AppleScript forum.


>>p.s. If there is some documentation I should be reading so I don't 
>>ask these simple questions, please point me to it.
>
>There isn't really any.

The AppleScript Language Guide explains how application scripting 
operates, though it's all mixed in with AppleScript language-specific 
stuff, which is a bit irritating. (I hate that Apple always insist on 
mooshing application scripting and AppleScript language together like 
this when they're two completely different things. <sigh>Guess that's 
Apple for you...)

FWIW, the AppScripting 0.2.0 manual does describe all currently 
supported reference forms, along with various examples that should 
give you an idea of how they can be used. Individual application 
dictionaries will tell you which reference forms are supported for 
which elements, as well as describing the general containment 
structure. (Though they leave you to work out which commands work on 
which objects; a well-known flaw that'll eventually be fixed once 
sdefs replace aetes.)

If you look at AppScripting as providing a query-style interface that 
happens to use Python syntax, rather than a conventional object model 
(unless you're using an object model that happens to have built-in 
array processing support, that is), then I think you'll find it 
easier to grasp the basic principles.

That still leaves you to learn the particular vagaries (read: bugs, 
quirks and inconsistencies) of individual applications, of course. 
Apple doesn't seem to do an HCI guide on scripting interface design, 
unfortunately, and there's an awful lot of variation in both style 
and quality from app to app. A few apps do come with additional 
documentation and/or example scripts included; beyond that it's a 
case of searching out third-party scripts for examples of use (e.g. 
see <http://www.macscripter.net>), asking around the mailing lists, 
and good old trial-and-error. A good place to start is by practising 
on basic applications that have good scripting implementations: 
Tex-Edit Plus, for example; Finder's also quite good (though does 
have some longstanding bugs). Once you get the hang of how app 
scripting should ideally work, you'll find it much easier dealing 
with other apps that don't get it quite so right.

Welcome to the weird and wonderful - and frequently frustrating - 
world of application scripting, ;)

has
-- 
http://freespace.virgin.net/hamish.sanderson/



More information about the Pythonmac-SIG mailing list