• 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: Mon, 3 Sep 2001 12:42:35 -0500

On Sunday, September 2, 2001, at 11:27 PM, Neal A. Crocker wrote:

I'm not absolutely posittive, but I believe create/make commands are actually sent to the current Applescript "tell target" (assuming that that object has a method to handle it), which must, of course be able to contain the kind of object which is to be created. For instance, suppose the .scriptSuite file of the application specifies NSCoreSuite.Create as a supported commmand for the application/NSApplication object, indicating that it is to be handled by the "handleCreateCommand:" method. Suppose also that NSApplictation is given a "handleCreateCommand:" method (by using the categories mechanism, or subclassing). The following Applescript would cause a create/make event to be sent to the application/NSApplication object (thus invoking "handleCreateCommand:" method of NSApplication object) asking for the creation of a document/(NSDocument subclass) object:

tell application "Some Cocoa App.app"
make new document at before front document
end tell

This hypothesis can be easily tested, of course, and I mean to do it eventually.

I just tested this myself, and it does seem to work. It looks like all create commands are sent to the application object, regardless of the current tell target or even the insertion container. To do it, I just added NSCoreSuite.Create to NSApplication's SupportedCommands dictionary and specified a method, handleCreateScriptCommand:, which is now declared as a category on NSApplication. I did the same to SKTDrawDocument, but like I said, it looks like NSApplication handles all create commands.

For tests, I ran the following scripts on Sketch, and all invoked the same method on NSApplication:

tell application "Sketch" to make new document at end of documents

tell application "Sketch" to make new circle at end of graphics of front document

tell front document of application "Sketch" to make new circle at end of graphics

I played around with the Sketch example project and the debugger after my original post on this thread what I saw is entirely consistent with your conclusions about NSCreateCommand. Specifically, I put a break in the init method for the Sketch document class and used Applescript to send a "make new document" event to Sketch. Near as I can tell, NSCreateCommand does have a (totally undocumented) "performDefaultImplementation:" method which eventually calls the "init:" method for an instance of the kind of object to be created.

I also found another way to override create commands by making my own command class and declaring it in the Sketch scripting dictionary. I basically put a duplicate of the Create entry in NSCoreSuite's Commands dictionary, except with the CommandClass being set to my own "SKTCreateCommand" subclass of NSCreateCommand. Of course, to do this you also have to specify that AbstractObject will respond to "Sketch.Create" and not just "NSCoreSuite.Create", or you'll get an error saying that the receiver can't handle the command.

Of particular interest, this documentation page says:

"The description of a class (in a suite definition) includes a section for commands supported by the class. In this section you can either indicate that the default implementation (WHICH IS BASED ON KEY-VALUE CODING) for a command is sufficient, or you can specify a method that you want to handle the command when it is executed...." (The emphasis supplied by using all caps is mine.)

I think this is just saying that the default implementation retrieves all of the objects pointed to by the object specifiers passed into the command via key-value coding. In your own implementation, you could choose to evaluate the object specifiers manually instead of using key-value coding.

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


  • Follow-Ups:
    • Re: Implementing behavior for "make" appleevent in Cocoa App
      • From: "Neal A. Crocker" <email@hidden>
References: 
 >Re: Implementing behavior for "make" appleevent in Cocoa App (From: "Neal A. Crocker" <email@hidden>)

  • Prev by Date: Re: creating users programatically
  • Next by Date: Re: [Semi-OT] Using just the decimal
  • Previous by thread: Re: Implementing behavior for "make" appleevent in Cocoa App
  • Next by thread: Re: Implementing behavior for "make" appleevent in Cocoa App
  • Index(es):
    • Date
    • Thread