简体   繁体   中英

Why do I get error -1708 when executing an AppleScript for a program that I wrote?

I'm trying to add AppleScript support to a program that I wrote. It should be fairly straightforward, and I've pared it down to the absolute basics - but still I get error -1708.

The sdef for my program is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="AppleScript Test">
    <suite name="AppleScript Test Suite" code="ASTS" description="AppleScript Test Scripts">
        
        <command name="open" code="aevtodoc" description="Open a document.">
            <direct-parameter description="The file(s) to be opened.">
                <type type="file"/>
                <type type="file" list="yes"/>
            </direct-parameter>
            <result description="The opened document(s).">
                <type type="document"/>
                <type type="document" list="yes"/>
            </result>
        </command>

        <command name="quit" code="aevtquit" description="Quit the application.">
            <cocoa class="NSQuitCommand"/>
            <parameter name="saving" code="savo" type="save options" optional="yes" description="Should changes be saved before quitting?">
                <cocoa key="SaveOptions"/>
            </parameter>
        </command>

        <command name="run test" code="astsrunt" description="Run test code with a script">
            <cocoa class="RunTestCommand"/>
            <result type="text" description="A return string to show that it works okay"/>
        </command>
                
    </suite>
</dictionary>

The RunTestCommand class is implemented as follows:

RunTestCommand.h

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface RunTestCommand : NSObject

@end

NS_ASSUME_NONNULL_END

RunTestCommand.m

#import "RunTestCommand.h"

@implementation RunTestCommand

-(id)performDefaultImplementation {
    NSString* returnString = @"Hello World"; // <-- There's a breakpoint here which never gets tripped
    return returnString; 
}

@end

I have also made sure that the application is set to be scriptable and the sdef defined in the info.plist. When I drag the application onto the script editor, its dictionary shows correctly. That said, the following script results in error -1708 and doesn't complete.

Test Script

tell application "AppleScript Test Program"
    activate
    run test
end tell

My spidey sense tells me that this is a brown paper bag error, but I can't see it for looking. Can anyone suggest what the problem might be?

RunTestCommand needs to inherit from NSScriptCommand or one of its subclasses. Eg RunTestCommand.h should be:

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface RunTestCommand : NSScriptCommand

@end

NS_ASSUME_NONNULL_END

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM