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

Adding simple AppleScript commands to a Cocoa application


  • Subject: Adding simple AppleScript commands to a Cocoa application
  • From: "Robert Nolet" <email@hidden>
  • Date: Sun, 16 Apr 2006 13:46:15 +0000

Hi,

I've been trying to write a very simple cocoa application which implements several simple AppleScript commands with no arguments/parameters. Basically, i want to:

tell app "MyApp"
 do something
end tell

such that a

-(void) doSomething;

message is sent to MyController (subclass of NSObject, instantiated with Interface Builder). So far I have been able to realize this by setting MyController as the application delegate in Interface Builder, and subclassing NSScriptCommand as following:

@implementation MyCommand

- (id) performDefaultImplementation {
	[(MyController *)[[NSApplication sharedApplication] delegate] doSomething];
	return nil;
}

@end

My MyApp.sdef file contains the following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="MyApp Terminology">
<suite name="MyApp Suite" code="MyAp" description="MyApp scripting commands.">
<command name="do something" code="MyApDoSo"
description="Do something.">
<cocoa class="MyCommand"/>
</command>
</suite>
</dictionary>


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.

I'm sure it should be possible, but all the code examples I have found so far work by calling methods in data objects which are passed as parameters to the AppleScript command, and not for no-parameter commands.

Anybody have any suggestions?

Thanks,
-Robert Nolet

_________________________________________________________________
Chatten met je online vrienden via MSN Messenger. http://messenger.msn.nl/

_______________________________________________
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: Dustin Voss <email@hidden>
    • Re: Adding simple AppleScript commands to a Cocoa application
      • From: Jim Correia <email@hidden>
  • Prev by Date: Re: Open System Preferences?
  • Next by Date: Re: Adding simple AppleScript commands to a Cocoa application
  • Previous by thread: Re: Empty NSStrings, nil NSStrings
  • Next by thread: Re: Adding simple AppleScript commands to a Cocoa application
  • Index(es):
    • Date
    • Thread