• 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
AppleScipt & Cocoa, argh! I can't get it to work
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AppleScipt & Cocoa, argh! I can't get it to work


  • Subject: AppleScipt & Cocoa, argh! I can't get it to work
  • From: Nat! <email@hidden>
  • Date: Wed, 10 Apr 2002 23:29:56 +0200

I am still stuck in AppleScript and Cocoa. Maybe someone has an idea, what's going on/wrong ?

I have a NSApplication subclass called "Application" that provides objects of class "Stuff" in an NSArray. There is always one object in the "stuffs" array. The ScriptEditor reads my script suite correctly.

My test script is this:

tell application "AppleScriptTest"
set x to stuff 1
end tell

It works in as much, that it doesn't produce an error. Alas the variable 'x' does not get set. When I look into the event log I see:

tell application "AppleScriptTest"
get stuff 1
end tell

I see that there is no result sent back. A successful event log should look something like this

tell application "Sketch"
get document 1
--> stuff 1
end tell


So I wrote a little poser on NSScriptCommand to get some tracing facility in Cocoa too (It's appended in the back). The trace output shows that my method did return a "Stuff", it just seems to get lost somewhere.

[here is the trace, somewhat beautified for readability. The log comes from -[NSScriptCommand executeCommand] ]

-> Execute Command: NSCoreSuite.Get
Direct Parameter: <NSIndexSpecifier: stuffs 1>
Receivers: <NSIndexSpecifier: stuffs 1>
Arguments: {}
<- Stuff:<Stuff: 0x975b0>

hmmm.... The stuff gets send back from my code into the Cocoa machinery, but then it vanishes.

If anyone can help, It'd be great. Appended are various relevant files.

Cheers
Nat!


OK here comes the scriptSuite and the scriptTerminology.

{
AppleEventCode = ASCT;
Classes = {
Application = {
AppleEventCode = capp;
Superclass = NSCoreSuite.AbstractObject;
ToManyRelationships = {stuffs = {AppleEventCode = sTuf; ReadOnly = YES; Type
= Stuff; }; };
};
Stuff = {
AppleEventCode = sTuf;
Superclass = NSCoreSuite.AbstractObject;
SupportedCommands = {XXX.Printa = "print:"; };
};
};
Commands = {
Printa = {
AppleEventClassCode = aevt;
AppleEventCode = Pdoc;
CommandClass = NSScriptCommand;
Type = "";
};
};
Name = XXX;
}

-----
{
Classes = {
Application = {
Description = "This class represents those, um, whatchamacallits.";
Name = application;
PluralName = applications;
};
Stuff = {
Attributes = {};
Description = "This class represents those, um, whatchamacallits.";
Name = stuff;
PluralName = stuffs;
};
};
Commands = {
Printa = {
Description = "This command frobs the receiver(s).";
IsVerb = YES;
Name = printa;
};
};
Description = "specific stuff";
Name = "Test Suite";
}

----
Here is the little posing debugger class
----

#import <Foundation/Foundation.h>


@interface DebugNSScriptCommand : NSScriptCommand
{
}

@end


@implementation DebugNSScriptCommand

+ (void) load
{
fprintf( stderr, "DebugNSScriptCommand posing as NSScriptCommand\n");
[self poseAsClass:[self superclass]];
}


- (id) executeCommand
{
id result;
int no;

NSLog( @"-> Execute Command: %@", self);
result = [super executeCommand];
switch( (no = [super scriptErrorNumber]))
{
case NSNoScriptError :
NSLog( @"<- %@:%@", [result class], [result description]);
break;

default :
NSLog( @"<- Error: %@",
[super scriptErrorString]);
break;
}

return( result);
}


@end


----

for completeness, here's Application and Stuff

#import <AppKit/AppKit.h>


@interface Application : NSApplication
{
NSMutableArray *stuffs_;
}

- (NSArray *) stuffs;

@end

----


#import "Application.h"
#import "Stuff.h"


@implementation Application

- (id) init
{
[super init];

stuffs_ = [[NSMutableArray alloc] init];
[stuffs_ addObject:[[Stuff new] autorelease]];

return( self);
}


- (NSArray *) stuffs
{
NSLog( @"%s Returning stuffs: %@", __PRETTY_FUNCTION__, stuffs_);
return( stuffs_);
}

@end

----


#import <Foundation/Foundation.h>


@interface Stuff : NSObject
{
}

- (void) print:(id) sender;

@end

----

#import "Stuff.h"


@implementation Stuff

- (void) print:(id) sender
{
NSLog( @"%s %@ %@", __PRETTY_FUNCTION__, [sender description], [self description]);
}


@end

------------------------------------------------------
Some people drink deep from the fountains of life, and
some just gargle. -- DLR
_______________________________________________
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.

  • Follow-Ups:
    • Re: AppleScipt & Cocoa, argh! I can't get it to work
      • From: Greg Titus <email@hidden>
  • Prev by Date: ScreenSaver & Bundles
  • Next by Date: Is it valid to call exit(-1); in a Cocoa Application, will it terminate OK
  • Previous by thread: Re: ScreenSaver & Bundles
  • Next by thread: Re: AppleScipt & Cocoa, argh! I can't get it to work
  • Index(es):
    • Date
    • Thread