为什么在为我编写的程序执行 AppleScript 时出现错误 -1708?
Why do I get error -1708 when executing an AppleScript for a program that I wrote?
我正在尝试将 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>
RunTestCommandclass实现如下:
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
我还确保应用程序设置为可编写脚本并且 sdef 在 info.plist 中定义。当我将应用程序拖到脚本编辑器上时,它的字典显示正确。也就是说,以下脚本导致错误 -1708 并且未完成。
测试脚本
tell application "AppleScript Test Program"
activate
run test
end tell
我的直觉告诉我这是一个牛皮纸袋的错误,但我看不出来。任何人都可以提出可能是什么问题吗?
RunTestCommand 需要继承自 NSScriptCommand 或其子类之一。例如。 RunTestCommand.h 应该是:
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface RunTestCommand : NSScriptCommand
@end
NS_ASSUME_NONNULL_END
我正在尝试将 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>
RunTestCommandclass实现如下:
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
我还确保应用程序设置为可编写脚本并且 sdef 在 info.plist 中定义。当我将应用程序拖到脚本编辑器上时,它的字典显示正确。也就是说,以下脚本导致错误 -1708 并且未完成。
测试脚本
tell application "AppleScript Test Program"
activate
run test
end tell
我的直觉告诉我这是一个牛皮纸袋的错误,但我看不出来。任何人都可以提出可能是什么问题吗?
RunTestCommand 需要继承自 NSScriptCommand 或其子类之一。例如。 RunTestCommand.h 应该是:
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface RunTestCommand : NSScriptCommand
@end
NS_ASSUME_NONNULL_END