Re: Getting objectSpecifier right...
Re: Getting objectSpecifier right...
- Subject: Re: Getting objectSpecifier right...
- From: Dustin Voss <email@hidden>
- Date: Sat, 9 Oct 2004 15:44:15 -0700
On 9 Oct, 2004, at 1:13 PM, Doug Knowles wrote:
I'm getting the classic '«class » id 2 of document "Untitled"' response trying to get a reference to an object within my document via AppleScript.
The object in question is a member of a subclass of the class that has the objectSpecifier method (pasted below) which is returning the result.
Right. Gotcha.
A couple of notes:
- I am trying to build an object specifier that identifies the object by unique id within the document; specifying by index would be difficult, and slow if I have to enumerate all objects of the class (I'm anticipating thousands in normal usage).
- I'm fuzzy on what the "class description" argument should be for initWithContainerClassDescription. I assume it should be the class description for the object itself; I tried using both the result of classDescriptionForClass (commented out below), and digging out of the suite registry. But I'm guessing based on various samples I have studied.
Actually, no. It should be the class description for the container. The easiest way to get this is to call
(NSScriptClassDescription *) [[self repository] classDescription], assuming I read your code right. There is no need to check with the suite registry.
I wrote a guide for supporting AppleScript with Cocoa—the most complete I've seen—at <http://cocoadev.com/?HowToSupportAppleScript>. If you haven't checked it out already, you should.
- (NSScriptObjectSpecifier *)objectSpecifier
{
NSLog( @"Category: objectSpecifier requested for %@", [self recordDescription] );
// try to specify the category by id
NSScriptObjectSpecifier *containerRef = [[self repository] objectSpecifier];
// NSScriptClassDescription *classDesc = (NSScriptClassDescription *)[NSScriptClassDescription classDescriptionForClass:[Category class]];
NSScriptSuiteRegistry *reg = [NSScriptSuiteRegistry sharedScriptSuiteRegistry];
NSDictionary *classes = [reg classDescriptionsInSuite:@"Prospector"];
NSScriptClassDescription *classDesc = [classes objectForKey:@"Category"];
NSLog( @"...found category description %@", classDesc );
NSNumber *myID = [[NSNumber alloc] initWithLong:[self recordID]];
NSUniqueIDSpecifier *spec = [[NSUniqueIDSpecifier alloc] initWithContainerClassDescription:classDesc containerSpecifier:containerRef key:@"recordID" uniqueID:myID];
return spec;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden