• 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: Adding scripting support to Cocoa applications
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding scripting support to Cocoa applications


  • Subject: Re: Adding scripting support to Cocoa applications
  • From: email@hidden
  • Date: Mon, 10 Mar 2003 17:23:55 -0800 (PST)

>> When I try to instantiate an object of class foo in Applescript with:
>>
>> tell application "MyApp"
>> make new foo at the beginning of foos
>> end tell
>>
>> I get an error: NSCannotCreateScriptCommandError

> Does your script terminology have a class NSApplication corresponding
> to the application property, with superclass NSApplication?

Yes, it does now. I have a GNUMail class that has a superclass of
NSCoreSuite.NSApplication. It has an Apple Event Code of 'capp' and is
referenced by application (plural applications) in the scriptTerminology.

> And does your NSApplication class have a many-to-many relationship of
> type "Foo" named "foos" with the same AppleEvent code as your "Foo"
> class? Having the same AppleEvent code is important; Suite Modeler
> will show it in blue, indicating that it's a duplicate -- in this
> case being a duplicate is a *good* thing.

Yes, it does now. My custom class I am trying to script is "Message". Message's
superclass is NSCoreSuite.AbstractObject, its Apple Event Code is 'Gmsg', and is
referenced by "mail message" (plural "mail messages") in the scriptTerminology.

The application class GNUMail has a many-to-many relationship with
"mailMessages" which are of type "Message" and have an Apple Event Code of
'Gmsg'.

> And finally, does your NSApplication delegate implement
> -application:delegateHandlesKey: along with a mutable array key for
> "foos"?

Yes. GNUMail is my application delegate and implements:

- (BOOL)application:(NSApplication *)sender delegateHandlesKey:(NSString *)key
{
NSLog(@"key = %@", key);
return [key isEqualToString:@"mailMessages"];
}

- (NSMutableArray *) mailMessages
{
NSLog(@"returning message list...");
// Just a test, return an empty array.
return ([[[NSMutableArray alloc] init] autorelease]);
}


> If you have all of the above, then your script should work.

It almost does. This is my test script:

tell application "GNUMail"
make new mail message
end tell

I can see that a new "Message" object is being instantiated in my code, but I
still get a script error: NSArgumentsWrongScriptError

When I try

tell application "GNUMail"
make new mail message at the beginning of mail messages
end tell

a new object is created, but I get the error: NSContainerSpecificError

Finally, when I try

tell application "GNUMail"
make new mail message in front
end tell

then it seems to work OK. The object is created, and I don't get any error. But
why is it not working in the first two cases?

I tried specifying "LocationRequiredToCreate = NO" in my "ToManyRelationships"
of mailMessages of the scriptSuite, but it did not change anything.

I am posting my scriptSuite and scriptTerminology in case anybody can see an
error. I have not yet specified any attributes in my classes. Is that a problem?

Thanks for any help.

Ujwal

GNUMail.scriptSuite:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd";>
<plist version="1.0">
<dict>
<key>AppleEventCode</key>
<string>GMAL</string>
<key>Classes</key>
<dict>
<key>GNUMail</key>
<dict>
<key>AppleEventCode</key>
<string>capp</string>
<key>Attributes</key>
<dict/>
<key>Superclass</key>
<string>NSCoreSuite.NSApplication</string>
<key>SupportedCommands</key>
<dict/>
<key>ToManyRelationships</key>
<dict>
<key>mailMessages</key>
<dict>
<key>AppleEventCode</key>
<string>Gmsg</string>
<key>ReadOnly</key>
<string>NO</string>
<key>Type</key>
<string>Message</string>
</dict>
</dict>
</dict>
<key>Message</key>
<dict>
<key>AppleEventCode</key>
<string>Gmsg</string>
<key>Attributes</key>
<dict/>
<key>Superclass</key>
<string>NSCoreSuite.AbstractObject</string>
<key>SupportedCommands</key>
<dict/>
<key>ToManyRelationships</key>
<dict/>
</dict>
</dict>
<key>Commands</key>
<dict>
<key>GetURL</key>
<dict>
<key>AppleEventClassCode</key>
<string>GURL</string>
<key>AppleEventCode</key>
<string>GURL</string>
<key>CommandClass</key>
<string>GetURLScriptCommand</string>
</dict>
<key>OpenURL</key>
<dict>
<key>AppleEventClassCode</key>
<string>gurl</string>
<key>AppleEventCode</key>
<string>gurl</string>
<key>CommandClass</key>
<string>GetURLScriptCommand</string>
</dict>
</dict>
<key>Name</key>
<string>GNUMail</string>
</dict>
</plist>


GNUMail.scriptTerminology:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd";>
<plist version="1.0">
<dict>
<key>Classes</key>
<dict>
<key>GNUMail</key>
<dict>
<key>Attributes</key>
<dict/>
<key>Description</key>
<string>GNUMail's top level scripting object</string>
<key>Name</key>
<string>application</string>
<key>PluralName</key>
<string>applications</string>
</dict>
<key>Message</key>
<dict>
<key>Attributes</key>
<dict/>
<key>Description</key>
<string>This class represents a message object</string>
<key>Name</key>
<string>mail message</string>
<key>PluralName</key>
<string>mail messages</string>
</dict>
</dict>
<key>Commands</key>
<dict>
<key>GetURL</key>
<dict>
<key>Description</key>
<string>Open a mailto URL</string>
<key>Name</key>
<string>get URL</string>
</dict>
<key>OpenURL</key>
<dict>
<key>Description</key>
<string>Open a mailto URL</string>
<key>Name</key>
<string>open URL</string>
</dict>
</dict>
<key>Description</key>
<string>Commands to control GNUMail</string>
<key>Name</key>
<string>GNUMail commands</string>
</dict>
</plist>
_______________________________________________
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: Cocoa friendly Quicktime APIs?
  • Next by Date: Re: nib corruption - please help
  • Previous by thread: Re: Adding scripting support to Cocoa applications
  • Next by thread: File Manipulation
  • Index(es):
    • Date
    • Thread