• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: AppleScipt & Cocoa, argh! I can't get it to work
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AppleScipt & Cocoa, argh! I can't get it to work


  • Subject: Re: AppleScipt & Cocoa, argh! I can't get it to work
  • From: Nat! <email@hidden>
  • Date: Thu, 11 Apr 2002 23:50:17 +0200

Am Donnerstag den, 11. April 2002, um 03:08, schrieb Greg Titus:

You need to implement the -objectSpecifier method on your Stuff class. Cocoa's AppleScript support calls this method to turn your object into a reference to give to AppleScript.

In your simple case it should look like:

- (NSScriptObjectSpecifier *)objectSpecifier;
{
NSScriptObjectSpecifier *containerRef = [NSApp objectSpecifier];

return [[[NSIndexSpecifier alloc] initWithContainerClassDescription:[containerRef keyClassDescription] containerSpecifier:containerRef key:@"stuff" index:0] autorelease];
}

(See Sketch for a more complete example.)

Hope this helps,
--Greg

Oh it helped indeed. It moved a great conceptual boulder out of the way. I finally, finally! after a week of fruitless laboring got my AppleScript to work.

Starting with your code, I slightly changed it to:

- (NSScriptObjectSpecifier *) objectSpecifier
{
NSScriptObjectSpecifier *containerRef;
NSIndexSpecifier *specifier;
id classDescription;

containerRef = [NSApp objectSpecifier];
classDescription = [NSClassDescription classDescriptionForClass:[NSApp class]];

specifier = [[[NSIndexSpecifier alloc] initWithContainerClassDescription:classDescription
containerSpecifier:containerRef
key:@"stuffs"
index:0] autorelease];
return( specifier);
}

I saw that [NSApp objectSpecifier] returns nil. That is I think OK, because NSApp is the root object. But I found that the classDescription was needed to be valid, otherwise my script would not know that "Stuff" objects were returned. Now

tell application "AppleScriptTest"
set x to stuff 1
end tell

finally worked!

[Looking in the documentation, I don't see the "objectSpecifier" method ever mentioned; file:///Developer/Documentation/Cocoa/TasksAndConcepts/ProgrammingTopics/Scriptability/
Tasks/ScriptabilityGuidelines.html, doesn't say anything about having to code this.]


But behold! There is another boulder :)


Something can't be right. It looks like the object MUST be aware of it's container to be able to produce the NSScriptObjectSpecifier. The object must know the key it is accessed with in the container class ? Ugh! This can't be true! Sketch unfortunately just looks the same to me and doesn't help.

And behold again! More blockage :)

As my next block in the road I found and stalled at "toOneRelationships". I just created another class called OtherStuff, just the same as Stuff. I put a "ToOneRelationship" "otherstuff" on Application and tried:

tell application "AppleScriptTest"
set x to otherstuff
printa x
end tell

The Yield is this strange happening (Direct Parameter ???):

2002-04-11 23:37:35.194 AppleScriptTest[373] -> Execute Command: XXX.Printa
Direct Parameter: 1867806054
Receivers: (null)
Arguments: {}
2002-04-11 23:37:35.194 AppleScriptTest[373] <- (null):(null)

Again, help help! :)

Cheers
Nat!

scriptSuite diff
--- [on Application ] ---
<key>ToOneRelationships</key>
<dict>
<key>otherstuff</key>
<dict>
<key>AppleEventCode</key>
<string>oTuf</string>
<key>ReadOnly</key>
<string>YES</string>
<key>Type</key>
<string>OtherStuff</string>
</dict>
</dict>
-- [on Classes ] ---
<key>OtherStuff</key>
<dict>
<key>AppleEventCode</key>
<string>oTuf</string>
<key>Superclass</key>
<string>NSCoreSuite.AbstractObject</string>
<key>SupportedCommands</key>
<dict>
<key>XXX.Printa</key>
<string>print:</string>
</dict>
</dict>

---
scriptTerminology diff

<key>OtherStuff</key>
<dict>
<key>Attributes</key>
<dict/>
<key>Description</key>
<string>This class represents those, um, whatchamacallits.</string>
<key>Name</key>
<string>otherstuff</string>
<key>PluralName</key>
<string>otherstuffs</string>
</dict>

---
OtherStuff.m diff to Stuff.m

- (NSScriptObjectSpecifier *) objectSpecifier
{
NSScriptObjectSpecifier *containerRef;
NSIndexSpecifier *specifier;
id classDescription;

containerRef = [NSApp objectSpecifier];
classDescription = [NSClassDescription classDescriptionForClass:[NSApp class]];

// containerRef = nil;
// classDescription = nil;

specifier = [[[NSPropertySpecifier alloc] initWithContainerClassDescription:classDescription
containerSpecifier:containerRef
key:@"otherstuff"] autorelease];
return( specifier);
}

---

Application.m diff

- (id) init
{
[super init];

otherstuff_ = [OtherStuff new];

stuffs_ = [[NSMutableArray alloc] init];
[stuffs_ addObject:[[Stuff new] autorelease]];
[self myColor];
return( self);
}

- (OtherStuff *) otherStuff
{
return( otherstuff_);
}

------------------------------------------------------
Some people drink deep from the fountains of life, and
some just gargle. -- DLR
_______________________________________________
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.

  • Follow-Ups:
    • Re: AppleScipt & Cocoa, argh! I can't get it to work
      • From: Greg Titus <email@hidden>
References: 
 >Re: AppleScipt & Cocoa, argh! I can't get it to work (From: Greg Titus <email@hidden>)

  • Prev by Date: Re: Symbolic links, alias files and related stuff
  • Next by Date: [ANN] Some new Mulle stuff
  • Previous by thread: Re: AppleScipt & Cocoa, argh! I can't get it to work
  • Next by thread: Re: AppleScipt & Cocoa, argh! I can't get it to work
  • Index(es):
    • Date
    • Thread