• 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 simple AppleScript commands to a Cocoa application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding simple AppleScript commands to a Cocoa application


  • Subject: Re: Adding simple AppleScript commands to a Cocoa application
  • From: Dustin Voss <email@hidden>
  • Date: Tue, 18 Apr 2006 19:53:47 -0700

On 16 Apr 2006, at 6:46 AM, Robert Nolet wrote:

This all works exactly as I want it to, however I think that creating a subclass of NSScriptCommand and then accessing my MyController object by going through the application delegate is an incredibly sloppy and round-about way of achieving this. Also, if I were to add more commands, I would have to create a new class for each command I want to implement. So I am looking for a more elegant way of linking methods in my MyController class to AppleScript commands.

This *is* the elegant way to do it.

In Apple Script, commands are independent from any particular class. Thus, the command itself needs to have its own execution code. As an example of why this is necessary, I give you two contrasting statements: "sum cells 1 thru 4 of spreadsheet 1" and "sum (cell 1 of spreadsheet 1, cell 1 of spreadsheet 2, cell 1 of spreadsheet 3)".

In the first statement, spreadsheet 1 can do the sums, but in the second statement, no one spreadsheet can do the job. There is a list object, but what are the odds that the developer would anticipate that list objects would need to be able to do sums? Therefore the sum command needs to do its own work.

The problem is that Objective-C does not have the concept of object- independent actions. The closest it has is NSInvocation, and even that is meaningless until it is tied to one, specific object.

In your particular case, you don't want the command's functionality to be where it would naturally be, which is in the NSScriptCommand sub-class. Instead, you want the command's functionality to be in the delegate object. So, you are using NSScriptCommand sub-classes to simply forward the command to the proper actor, which is absolutely correct.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Adding simple AppleScript commands to a Cocoa application
      • From: Ondra Cada <email@hidden>
References: 
 >Adding simple AppleScript commands to a Cocoa application (From: "Robert Nolet" <email@hidden>)

  • Prev by Date: Re: Adding simple AppleScript commands to a Cocoa application
  • Next by Date: Re: [Q] COM and dynamic link library?
  • Previous by thread: Re: Adding simple AppleScript commands to a Cocoa application
  • Next by thread: Re: Adding simple AppleScript commands to a Cocoa application
  • Index(es):
    • Date
    • Thread