Cocoa AppleScript for Free?
Cocoa AppleScript for Free?
- Subject: Cocoa AppleScript for Free?
- From: John Nairn <email@hidden>
- Date: Tue, 16 Sep 2003 16:42:17 -0600
I am trying to figure out the claimed "AppleScript" for free in Cocoa
applications (only free if you ignore the cost of time required for
extensive experimentation to figure out how to do it with minimal help
from documentation).
In order for my application, which has several document types, to work
with multiple documents, I added ToManyRelationships to my
NSApplication class for the various document types (orderedCommands and
orderedResults). Neither of these document types could be "docu"
because that would corrupt object inheritance. They each must have
their own unique code. With this suite, the AppleScript command
make at front new commands document
leads to the "free" AppleScripting calling insertInOrderedCommands
which I implemented as:
- (void)insertInOrderedCommands:(CommandDocument *)doc
atIndex:(unsigned)index
{
[[NSDocumentController sharedDocumentController]
openUntitledDocumentOfType:@"FEA or MPM Commands
Document"
display:YES];
}
FIRST PROBLEMS:
1. The CommandDocument object is created before this call and I could
not find a way to insert that instance into a new window. My poor
solution was to create a new document and ignore the one sent for
insertion. It seems to work, but any properties from the make command,
such as
make new commands document at front with properties {text:"Hello World"}
will not work because, by experimentation, I found out that properties
are set BEFORE the call to insert the object.
2. According to all dictionaries, the "at" in make is optional, but all
attempts to "make new document" in Cocoa without an "at" complain there
is an error. Is Cocoa changing the "at" into mandatory despite the
settings of the dictionary?
3. Use of "with data" (also documented in make dictionary) causes an
error. I understand it might have no use and be ignored, but why is it
an AppleScript error?
SECOND PROBLEM
Despite the uncertainties above, the crippled make command is
acceptable for my current needs. A serious problem, however, is that
documents created as above do not reliably close. The commands
close front document
close front document saving in "somePathName"
always raise exceptions. They sometimes work and they sometimes cause
the application to crash. I can override handleCloseScriptCommand in my
document class. The crashes stop when the command is ignored. Passing
control on the NSDocument (with [super handleCloseScriptCommand:cmd])
again leads to crashes.
COMMENT
These problems all arise when deviating from standard model of single
document application. Free AppleScripts works for such simple
applications, but the moment I added a second document type, it seems
nothing is free any more?
------------
John Nairn (1-801-581-3413, FAX: 1-801-581-4816)
Web page:
http://www.eng.utah.edu/~nairn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.