• 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
AS in Cocoa prob (LONG)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AS in Cocoa prob (LONG)


  • Subject: AS in Cocoa prob (LONG)
  • From: David Haas <email@hidden>
  • Date: Tue, 20 May 2003 22:23:14 -0500

I've got a Cocoa app to which I'm trying to add Applescript support and
I've run into a problem. Particularly with a objects having a ToManyRelationships
with other copies of itself.

Yes, that first sentence has started many a message on this list. I've tried to
profit from the mistakes/teachings of others, and so I've looked over Sketch.app
as well as Don Briggs' examples, but I'm still not sure how to fix my problem.
Hopefully somebody can give me enough of a clue to get over my last little hump.

My app has an object (let's call it DHContainer) which has 3 member
variables: a NSString (accessed by name), a NSMutableArray
(accessed by childArray), and a "id" which is either a DHContainer or
the parent NSDocument (accessed by parent). The childArray holds
other DHContainers. In my script suite, I've set up DHContainer (called in
applescript dhcontainers) as having a ToManyRelationship with DHContainers,
called through childArray.

It's an NSDocument based application, and each Document has a single
instance of a DHContainer saved as the "rootContainer" (and accessible
from Applescript using "root container")

So I start up my Document, and add to the root container 2 new child
DHContainers (named "a" and "b"). To container "b", I add a child container
named "c".

Then I write (and run) the following applescript:

tell application "MyApp"
set rc to the root container of the front document
repeat with i from 1 to number of dhcontainers in rc
set level1tc to dhcontainer i of rc
set n to name of level1tc
display dialog "the name is " & n
set level1count to number of dhcontainers in level1tc
if level1count is greater than 1 then
repeat with j from 1 to level1count
set level2tc to dhcontainer j of level1tc
set l2n to name of level2tc
display dialog "the name is "&l2n
end repeat
end if
end repeat
end tell

The script runs fine for "a" and "b", but gets an error at the line "set l2n to name of level2tc". If I replace all references to level2tc with "dhcontainer j of level1tc", things
work fine. Basically, level2tc isn't getting defined, or isn't staying defined, or isn't
getting defined in a usable way. (BTW - if there's a syntax error in what I've written,
it's 'cause I didn't cut & paste from script editor)

My DHContainer class has the following implementation of objectSpecifier
(swiped from Sketch.app, and only slightly modified). Anybody see anything
clearly wrong, or that would prevent the second-level (and thus, I imagine, the
3rd, or 4th, or 5th . . .) deep objects from being referenced correctly?

Any and all help greatly appreciated!

- (NSScriptObjectSpecifier *)objectSpecifier
{
id parent = [self parent];
NSScriptObjectSpecifier *containerRef = [parent objectSpecifier];
if ([parent isKindOfClass:[DHContainer class]]) {
unsigned index = [[parent childArray] indexOfObjectIdenticalTo:self];
if (index != NSNotFound) {
return [[[NSIndexSpecifier allocWithZone:[self zone]] initWithContainerClassDescription:[containerRef keyClassDescription] containerSpecifier:containerRef key:@"childArray" index:index] autorelease];
} else
return nil;
} else // top level - it's owned by the document
return [[[NSPropertySpecifier allocWithZone:[self zone]] initWithContainerSpecifier:containerRef key:@"rootContainer"] autorelease];
}
_______________________________________________
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.
  • Prev by Date: Re: try / finally
  • Next by Date: Re: utility window hides parent window?
  • Previous by thread: Re: File Package without NSDocument
  • Next by thread: Notification received twice
  • Index(es):
    • Date
    • Thread