Further scripting mysteries
Further scripting mysteries
- Subject: Further scripting mysteries
- From: email@hidden
- Date: Tue, 19 Mar 2002 22:21:29 -0800
OK. Emboldened by Greg & Brian's replies, I embarked upon the journey
of adding scripting support to my app. Needless to say, I'm having
difficulties I can't figure out. Here's my Constrictor.scriptSuite file:
{
"Name" = "Constrictor";
"AppleEventCode" = "SSct";
"Classes" = {
"ConstrictorApp" = {
"Superclass" = "NSCoreSuite.NSApplication";
"AppleEventCode" = "capp";
"Attributes" = {
"frameRect" = {
"Type" = "NSArray";
"AppleEventCode" = "Fram";
};
};
};
};
}
and here's my Constrictor.scriptTerminology file:
{
"Name" = "Constrictor suite";
"Description" = "Constrictor specific classes.";
"Classes" = {
"ConstrictorApp" = {
"Name" = "application";
"PluralName" = "applications";
"Description" = "Constrictor's top level scripting object.";
"Attributes" = {
"frameRect" = {
"Name" = "frame";
"Description" = "The frame of Constrictor's frame";
};
};
};
};
}
These seem to look as expected in Script Editor, although I'm not sure
whether I should be using "ConstrictorApp" (my subclass of
NSApplication, registered as my app's principal class in my Info.plist)
or "NSApplication" -- I tried changing it and it didn't seem to matter.
I've been experimenting with using application:delegateHandlesKey:
versus implementing the "frameRect" in ConstrictorApp directly, and with
returning NO for +useStoredAccessor and
+accessInstanceVariablesDirectly, but none of this seems to matter a
whit. What I'm seeing is that the script:
tell application "Constrictor"
get frame
end tell
works correctly in all of the permutations I've tried, and returns an
array of NSNumbers that Script Editor correctly displays as the result,
while
tell application "Constrictor"
set frame to {100, 100, 128, 128}
end tell
fails in all cases. In gdb, I see the following backtraces (the
key-value coding methods on ConstrictorApp simply log and call super,
removing them makes no difference to the functionality of the app):
#0 0x7084b394 in NSLog ()
#1 0x000182c8 in -[ConstrictorApp(Scripting) valueForKey:] ()
#2 0x708a0884 in -[NSSetCommand makeReceiver:takeValue:] ()
#3 0x708a0f00 in -[NSSetCommand performDefaultImplementation] ()
#0 0x7084b394 in NSLog ()
#1 0x00018638 in -[ConstrictorApp(Scripting) frameRect] ()
#2 0x708b6534 in -[_NSSelectorGetBinding getValueFromObject:] ()
#3 0x7088d204 in -[NSObject valueForKey:] ()
#4 0x70ea7fd0 in -[NSApplication(NSScripting) valueForKey:] ()
#5 0x000182fc in -[ConstrictorApp(Scripting) valueForKey:] ()
#6 0x708a0884 in -[NSSetCommand makeReceiver:takeValue:] ()
#7 0x708a0f00 in -[NSSetCommand performDefaultImplementation] ()
#0 0x7084b394 in NSLog ()
#1 0x00018500 in -[ConstrictorApp(Scripting)
replaceValueAtIndex:inPropertyWithKey:withValue:] ()
#2 0x708a0a24 in -[NSSetCommand makeReceiver:takeValue:] ()
#3 0x708a0f00 in -[NSSetCommand performDefaultImplementation] ()
#0 0x7084b394 in NSLog ()
#1 0x000182c8 in -[ConstrictorApp(Scripting) valueForKey:] ()
#2 0x7088e05c in -[NSObject(NSScriptingKVCAdditions)
replaceValueAtIndex:inPropertyWithKey:withValue:] ()
#3 0x70ea7c80 in -[NSApplication(NSScripting)
replaceValueAtIndex:inPropertyWithKey:withValue:] ()
#4 0x0001853c in -[ConstrictorApp(Scripting)
replaceValueAtIndex:inPropertyWithKey:withValue:] ()
#5 0x708a0a24 in -[NSSetCommand makeReceiver:takeValue:] ()
#6 0x708a0f00 in -[NSSetCommand performDefaultImplementation] ()
#0 0x7084b394 in NSLog ()
#1 0x00018638 in -[ConstrictorApp(Scripting) frameRect] ()
#2 0x708b6534 in -[_NSSelectorGetBinding getValueFromObject:] ()
#3 0x7088d204 in -[NSObject valueForKey:] ()
#4 0x70ea7fd0 in -[NSApplication(NSScripting) valueForKey:] ()
#5 0x000182fc in -[ConstrictorApp(Scripting) valueForKey:] ()
#6 0x7088e05c in -[NSObject(NSScriptingKVCAdditions)
replaceValueAtIndex:inPropertyWithKey:withValue:] ()
#7 0x70ea7c80 in -[NSApplication(NSScripting)
replaceValueAtIndex:inPropertyWithKey:withValue:] ()
#8 0x0001853c in -[ConstrictorApp(Scripting)
replaceValueAtIndex:inPropertyWithKey:withValue:] ()
#9 0x708a0a24 in -[NSSetCommand makeReceiver:takeValue:] ()
#10 0x708a0f00 in -[NSSetCommand performDefaultImplementation] ()
(The frames past -[NSSetCommand performDefaultImplementation] are the
usual AE stuff, and look fine to me, given that they're ending up at
NSSetCommand as they ought to). As far as I can see, NSSetCommand is
*not* trying to do a takeValue:forKey: to set the frame as I would
expect, but is instead *getting* the frame, and then doing a
replaceValueAtIndex:inPropertyWithKey:withValue: to try to stuff the
value into element 0 of the frame's array. The log produced by that
call in my code is:
replaceValueAtIndex: 0 inPropertyWithKey: frameRect withValue: <CFArray
0x1a1c240 [0x8016024c]>{type = mutable-small, count = 4, values = (
0 : 100
1 : 100
2 : 128
3 : 128
)}
replaceValueAtIndex:inPropertyWithKey:withValue: gets the value of the
key again, presumably to have something to stuff into; but this
ultimately fails, for reasons that are not clear to me. (All
ScriptEditor gives me is an NSInternalScriptError, and
handleTakeValue:forUnboundKey: is never called). It's unclear why
NSSetCommand got the key's value before calling
replaceValueAtIndex:inPropertyWithKey:withValue:, given that it doesn't
seem to have any use for it -- perhaps it was checking that an element
at index 0 existed before trying to set it?
I can supply the -frameRect and -setFrameRect: methods on my app if
necessary, but I think they're actually quite irrelevant; NSSetCommand
never even attempts to find a setFrameRect: method, for some reason
(I've got log-and-call-super implementations for
handleTakeValue:forUnboundKey:, takeValue:forKey:, and
takeStoredValue:forKey:, so I think I would know). And that's at the
core of the problem, I think.
What's going on here? Any help would be greatly appreciated, I've
debugged this about as far as I know how...
Ben Haller
Stick Software
_______________________________________________
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.