我正在尝试将AppleScript支持添加到我编写的程序中。它应该是相当简单的,我已经将它缩减到了绝对的基础-但我仍然得到了错误-1708。
我的程序的sdef如下:
<?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
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface RunTestCommand : NSObject
@end
NS_ASSUME_NONNULL_ENDRunTestCommand.m
#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,并且不会完成。
测试脚本
tell application "AppleScript Test Program"
activate
run test
end tell我敏锐的感觉告诉我这是一个牛皮纸袋错误,但我看不到它。有没有人能建议一下问题出在哪里?
发布于 2021-05-01 01:28:15
RunTestCommand需要从NSScriptCommand或它的一个子类继承。例如,RunTestCommand.h应该是:
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface RunTestCommand : NSScriptCommand
@end
NS_ASSUME_NONNULL_ENDhttps://stackoverflow.com/questions/67337502
复制相似问题