• 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: Implementing behavior for "make" appleevent in Cocoa App
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Implementing behavior for "make" appleevent in Cocoa App


  • Subject: Re: Implementing behavior for "make" appleevent in Cocoa App
  • From: Brian Webster <email@hidden>
  • Date: Sun, 2 Sep 2001 19:12:56 -0500

On Sunday, September 2, 2001, at 09:40 AM, cocoa-dev-
email@hidden wrote:

As I understand it, if the decription of an object in an
app.'s .scriptSuite file fails to specify a method to handle the
create event and the object inherits from NSObject (as is the case
for the the application/NSApplication object in Sketch), an
NSCreateCommand object is created when a create event is sent to the
application object.

The make command is a special case of sorts since it doesn't have a direct object argument like most other commands. Commands with a direct object can have the default behavior overridden by specifying a key in the SupportedCommands key of the direct object's class. For example, if you write an Applescript that says "close front window", NSWindow handles the command by specifying the handleCloseScriptCommand: selector in its entry scripting dictionary and then implementing that method.

But, if there is no selector specified, then the performDefaultImplementation: method in the corresponding command class will be called instead. With NSCreateCommand, I think this will always be the case, as it does not have a direct object and so the default behavior can't be overridden by that mechanism.

If no other handling options exist, and
NSCreateCommand implements performDefualtImplementation:, this method
is invoked to handle the create event. So, does NSCreateCommand
implement this method? If so, what does this method do? Also, where
is it documented.

I'll answer the last question first: it's not documented anywhere. :(

As far as I can tell, NSCreateCommand does something along these lines:

1. Creates a new object of the given class. There's nothing special to this; it just does [[theClass alloc] init].
2. Sets the properties of the object specified in the "with properties {...}" clause of the AS command. It's basically equivalent to a bunch of set data events being executed, except they're all done in one fell swoop.
3. Inserts the newly created object in its container as appropriate. For instance, when executing "make new document at end of documents", it will insert the new document into its container (the application object) using key-value coding. Look in NSScriptKeyValueCoding.h for the "documentation" on the method names that can be used to perform insertion and deletion of objects.

Like I said, this isn't documented, but should be. I've just pieced it together from some stack traces and extrapolation.

Before the hypothetical
performDefualtImplementation: method of NSCreateCommand is invoked,
an attempt is made to locate a method to handle the NSCreatedCommand
using something called key-value coding.

Key-value coding is not used to locate method names for handling scripting commands. These names are obtained only from the scripting dictionary for the app (and the dictionaries of the frameworks it uses, of course).

Key-value coding is a default behavior for evaluating object specifier while executing a scripting command. The scripting dictionary maps Apple Event codes to property/element names, and then those names are used by key-value coding to retrieve the Cocoa object that corresponds to an object specifier record. The names are used to map to various method names, usually getter/setter methods or the more complicated ones for multi-value keys declared in NSScriptKeyValueCoding.h, but this is a different mechanism than the one used to find command implementation method names. In fact, it is possible to override key-value coding altogether and evaluate object specifiers manually, although this is unnecessary 99.9% of the time.

--
Brian Webster
email@hidden
http://www.owlnet.rice.edu/~bwebster


  • Prev by Date: Quitting the dock
  • Next by Date: OT: Quitting the dock - an endless saga uncovering the deepest secrets of OS X
  • Previous by thread: Re: Quitting the dock
  • Next by thread: Re: Implementing behavior for "make" appleevent in Cocoa App
  • Index(es):
    • Date
    • Thread