Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can't make ... of <<class >> into type reference



Thank you for your reply, it is very helpful for me to try to wrap around this. I would like to respectfully reply to some of your notes in hopes that you or someone can help me clear more cobwebs.

On Nov 15, 2007, at 4:56 PM, Christiaan Hofman wrote:

This will not work. You want it to be contained by the app, you probably did not even expose your app's delegate for scripting. So use containerSpecifier = nil and containerClassDescription = [NSClassDescription classDescriptionForClass:[NSApplication class]].

I agree that I wasn't properly specifying my app as the container. I have reread the guide and my specifier now agrees with your note. Here it is:


NSScriptClassDescription *containerClassDesc = (NSScriptClassDescription *)
[NSScriptClassDescription classDescriptionForClass:[NSApp class]];
return [[[NSNameSpecifier alloc] initWithContainerClassDescription:containerClassDesc
containerSpecifier:nil key:@"orders"
name:[self pNumber]] autorelease];



(pNumber is the order number)

However, I do believe that my app's delegate is exposed to scripting. After all, the following script worked (see the two scripts in my original post. One of them always worked fine):
"customer name of first scheduled order whose id is orderNumber"


It was only when I tried assigning my order to an applescript variable where it failed. (more on this below)

About your code, usually the "id" property is a unique id. This does not seem to be the case, so it's better not to use "id" for this name, but something like "number" or "order number" or something.

OK, I had struggled with that and have renamed it "number" on your advice. It is a unique order number, but it is not what I would call an enforced or guaranteed unique ID.


Also the reason it did not work is as Mike says, you're giving a location specifier, not an object specifier. Sometimes you can fix this by forcing an evaluation, either by using an intermediate variable or inserting a "get" command. So I think this should work:

set myOrder to (get first scheduled order whose id is orderNumber)

Actually, this fails the same way my code did, and this is my last remaining puzzle I think. How is it possible for this to work:


customer name of first order whose number is orderNumber

and yet this to fail??:
set myOrder to first order whose number is orderNumber
	
	customer name of myOrder

I think I must be misunderstanding some basic applescript concept, but, how is the result of "of first order whose number is orderNumber" any different from what gets assigned to myOrder in "set myOrder to first order whose number is orderNumber"??


Is it not the order object getting returned in each case? My current error from trying the second of the above snippets is "Scheduler got an error: NSReceiverEvaluationScriptError: 4"

I thank you,

Paul

On 15 Nov 2007, at 10:44 PM, Paul Bruneau wrote:

Thanks, Mike, I really like your idea and I will double check my - objectSpecifier method. In the meantime, here it is:

- (NSScriptObjectSpecifier *)objectSpecifier
{
unsigned index = [[[NSApp delegate] orders] indexOfObjectIdenticalTo:self];
if (index == NSNotFound)
{
return nil;
}

NSScriptObjectSpecifier *containerRef = [[NSApp delegate] objectSpecifier];
return [[[NSIndexSpecifier allocWithZone:[self zone]]
initWithContainerClassDescription:[containerRef keyClassDescription]
containerSpecifier:containerRef key:@"orders" index:index] autorelease];

}


It was copied and modified from Sketch which was done at the limit of my understanding after having read the Object Specifiers section of the docs repeatedly so it may be flawed.

But still I am bothered that it seems to be returning a valid order in the first script for use in this line:
customer name of first scheduled order whose id is orderNumber

But then it fails when the response is put into myOrder.

On Nov 15, 2007, at 4:26 PM, Mike Glass wrote:

I'm just guessing here, and maybe Matt or Christiaan or someone with more experience can set me straight if I'm wrong, but it seems like "first scheduled order whose id is orderNumber" is returning a row number (12) instead of the object you're expecting (scheduled order). Make sure you're implementing - (NSScriptObjectSpecifier *)objectSpecifier; on your Order class, and that it returns an NSScriptObjectSpecifier subclass that is useful to you (we use NSUniqueIDSpecifier because each of our CD objects has a unique id).

-
Mike Glass
email@hidden

On Nov 15, 2007, at 4:08 PM, Paul Bruneau wrote:

I want to thank everyone for helping me with my enumeration problem including the tips on the utilities.

I would like to trouble you for one more piece of assistance. I do not do so lightly--I have spent several hours trying to find the cause for this problem.

I am working on implementing applescript into my Cocoa application which is in development and I have it successfully getting and setting properties of the main objects (orders). I have also successfully implemented the core "make" command with properties which is very handy for having FileMaker create new objects in my app.

But I am being stumped by what seems like it ought to me such a simple script. First, this works:

tell application "Scheduler"
	activate
	
	set orderNumber to "24777"
	
	customer name of first scheduled order whose id is orderNumber
	
end tell

It returns the name of the customer.

But this next script fails with "Scheduler got an error: Can't make customer name of <<class >> 12 into type reference. Here is the script:

tell application "Scheduler"
	activate
	
	set orderNumber to "24777"
	
	set myOrder to first scheduled order whose id is orderNumber
	
	customer name of myOrder
	
end tell

For the life of me, I can't figure out why it fails when I try to use the variable myOrder.

I am concerned that in the error message the <<class >> part seems to have a blank class. That does not make sense to me but I don't know where to look.

I have posted my .sdef to this handy code review site:
http://objc.pastebin.com/m5da48033
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-implementors mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-implementors/email@hidden

This email sent to email@hidden
References: 
 >Can't make ... of <<class >> into type reference (From: Paul Bruneau <email@hidden>)
 >Re: Can't make ... of <<class >> into type reference (From: Mike Glass <email@hidden>)
 >Re: Can't make ... of <<class >> into type reference (From: Paul Bruneau <email@hidden>)
 >Re: Can't make ... of <<class >> into type reference (From: Christiaan Hofman <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.