首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么在为我编写的程序执行AppleScript时出现错误-1708?

为什么在为我编写的程序执行AppleScript时出现错误-1708?
EN

Stack Overflow用户
提问于 2021-05-01 00:39:26
回答 1查看 40关注 0票数 0

我正在尝试将AppleScript支持添加到我编写的程序中。它应该是相当简单的,我已经将它缩减到了绝对的基础-但我仍然得到了错误-1708。

我的程序的sdef如下:

代码语言:javascript
复制
<?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>

RunTestCommand类的实现方式如下:

RunTestCommand.h

代码语言:javascript
复制
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface RunTestCommand : NSObject

@end

NS_ASSUME_NONNULL_END

RunTestCommand.m

代码语言:javascript
复制
#import "RunTestCommand.h"

@implementation RunTestCommand

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

@end

我还确保将应用程序设置为可脚本化,并在info.plist中定义sdef。当我将应用程序拖到脚本编辑器上时,它的字典显示正确。也就是说,下面的脚本会导致错误-1708,并且不会完成。

测试脚本

代码语言:javascript
复制
tell application "AppleScript Test Program"
    activate
    run test
end tell

我敏锐的感觉告诉我这是一个牛皮纸袋错误,但我看不到它。有没有人能建议一下问题出在哪里?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-01 01:28:15

RunTestCommand需要从NSScriptCommand或它的一个子类继承。例如,RunTestCommand.h应该是:

代码语言:javascript
复制
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface RunTestCommand : NSScriptCommand

@end

NS_ASSUME_NONNULL_END
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67337502

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档