I am so thankful for the kind help I have received from this list.
It has helped me to much better understand implementing Applescript
in my app. It was such good help that I felt sure that my new
command would work eventually, but it just won't.
I would like to describe what I have done and see if anyone spots
anything missing. I am using the steps outlined on Script Commands
Overview, although I have read through the entire guide many times
looking for clues:
http://developer.apple.com/documentation/Cocoa/Conceptual/
ScriptableCocoaApplications/SApps_script_cmds/
chapter_8_section_3.html#//apple_ref/doc/uid/20001242-SW2
My app is currently OK supporting getting and setting properties
via applescript, and I have successfully implemented the Core
command "make" to create new objects. Now I want to create a new
object-first command called "complete".
1. In my sdef, I provided a responds-to entry for my scheduled
order class (a subclass of order) that is meant to handle the command:
<class name="scheduled order" code="SORD" inherits="order"
description="An order that is currently scheduled for production.">
<cocoa class="Order"/>
<responds-to name="complete">
<cocoa method="complete:"/>
</responds-to>
</class>
2. Since it's a new applescript command, I added a command element
to my sdef. The following snippet appears directly below the above
one, inside my app's custom suite:
<!-- Commands -->
<command name="complete" code="SK3DCOMP" description="Complete an
object to indicate that work has been completed.">
<direct-parameter type="order"/>
</command>
</suite>
</dictionary>
Here is the whole sdef if you'd like to see it:
http://objc.pastebin.com/m3d4e48c0
3. In my implementation of my scriptable class (Order), I
implemented the named method:
from Order.h:
- (void)complete:(NSScriptCommand *)command;
from Order.m:
- (void)complete:(NSScriptCommand *)command;
{
NSLog(@"Order complete: %@", command);
NSLog (@"arguments: %@", [command evaluatedArguments]);
NSLog (@"receivers: %@", [command evaluatedReceivers]);
NSLog (@"direct param: %@", [command directParameter]);
}
I'm not subclassing NSScriptCommand because I believe for this
simple object-first command I don't need to.
When I call "complete myOrder" in script editor, I get "Scheduler
got an error: NSReceiversCantHandleCommandScriptError"
2007-11-19 10:09:54.500 Scheduler[571] Command: Intrinsics.get
Direct Parameter: <NSUniqueIDSpecifier: scheduledOrders with an ID
of "24778">
Receivers: <NSUniqueIDSpecifier: scheduledOrders with an ID of
"24778">
Arguments: {}
2007-11-19 10:09:54.500 Scheduler[571] key checked = scheduledOrders
2007-11-19 10:09:54.500 Scheduler[571] key checked = scheduledOrders
2007-11-19 10:09:54.500 Scheduler[571] key checked = scheduledOrders
2007-11-19 10:09:54.500 Scheduler[571] Property Value: 24778 (5)
2007-11-19 10:09:54.501 Scheduler[571] objectSpecifier: 24778 (7)
2007-11-19 10:09:54.501 Scheduler[571] Result:
<NSAppleEventDescriptor: 'obj '{ 'from':''null''(), 'want':'Ordr',
'form':'ID ', 'seld':'utxt'($32003400370037003800$) }
2007-11-19 10:09:54.516 Scheduler[571] Command: Scheduler
Suite.complete
Direct Parameter: <NSUniqueIDSpecifier: orders with an ID of "24778">
Receivers: <NSUniqueIDSpecifier: orders with an ID of "24778">
Arguments: {}
2007-11-19 10:09:54.516 Scheduler[571] key checked = orders
2007-11-19 10:09:54.517 Scheduler[571] key checked = orders
2007-11-19 10:09:54.517 Scheduler[571] key checked = orders
2007-11-19 10:09:54.517 Scheduler[571] Result: (null)
2007-11-19 10:09:54.517 Scheduler[571] Error: 4
"NSReceiversCantHandleCommandScriptError"
"key checked" is a log entry that is in my application:
delegateHandlesKey: method which resides in my AppController class
which is the app's delegate. I don't know why it gets called three
times in a row, but here is the method in case it looks crazy to
anyone:
- (BOOL)application:(NSApplication *)app
delegateHandlesKey:(NSString *)key;
{
NSLog(@"key checked = %@", key);
NSSet * keys = [NSSet setWithObjects:@"scheduledOrders",
@"orderEntryOrders", @"finishedOrders", @"orders", nil];
if ([keys member:key] != nil)
{
return YES;
} else {
return NO;
}
}
I am thankful for any ideas.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-implementors mailing list (Applescript-
email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-implementors/
email@hidden
This email sent to email@hidden