开发者

making an apple-scriptable application in Objective C, getting bizarre errors

开发者 https://www.devze.com 2023-01-04 05:13 出处:网络
Ok, so I\'ve got an application, and I want to make it scriptable. I set up the plist, I set up the sdef file.

Ok, so I've got an application, and I want to make it scriptable. I set up the plist, I set up the sdef file.

So far I have only one apple Event command: gotoPage. it takes an integer. and returns a boolean.

The relevant XML is:

    <command name="gotoPage" code="dcvwgoto" description="Goto a specified page">
        <cocoa class="AEGoto"/>
        <direct-parameter description="Page Number" type="integer"/>
        <result description="True if the page exists, False othrewise" type="boolean"/>
    </command>

I have an Objective-C class AEGoto.h:

@interface AEGoto :NSScrip开发者_运维问答tCommand {
}
- (id)performDefaultImplementation;


- (id)performDefaultImplementation
{
    int page = [[self directParameter] intValue];
    Boolean retval = [gController setPage: page];
    return retval? @"YES" : @"NO";
}

setPage: (int) is correct, and works fine.

When I call this, my program seems to work correctly. But then I get the error:

error "DocView got an error: 4 doesn’t understand the gotoPage message." number -1708 from 4

I also get, in my DocView output:

Error while returning the result of a script command: the result object... YES ...could not be converted to an Apple event descriptor of type 'boolean'. This instance of the class 'NSCFString' doesn't respond to -scriptingBooleanDescriptor messages.

However, if I return just the straight Boolean, I get:

Single stepping until exit from function -[NSScriptingAppleEventHandler handleCommandEvent:withReplyEvent:], which has no line number information. Program received signal: “EXC_BAD_ACCESS”.

so, I guess I've got 2 questions: 1) Why does it think it wants to tell 3 to goto a page? and 2) what is the correct way to return a Boolean from the applescript?

thanks.


return [NSNumber numberWithBool:retval];

0

精彩评论

暂无评论...
验证码 换一张
取 消