编辑:我已经解决了这个问题;这是一个配置问题。确保您的.sdef是与您的应用程序一起复制/部署的,否则在运行时找不到它。
我正在使用Mono和Monobjc构建一个Mac应用程序,我希望能够通过AppleScript发送命令。我已经阅读了Apple文档,并获得了使用Objective的简单脚本动词示例,但我似乎无法将其翻译为使用Monobjc。内置命令如“退出”工作,但我在脚本定义中添加的命令的自定义套件在目标C版本中工作,但在单一版本中不能工作。正在使用的脚本定义是Stest.sdef:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<!-- declare the namespace for using XInclude so we can include the standard suite -->
<dictionary xmlns:xi="http://www.w3.org/2003/XInclude">
<!-- use XInclude to include the standard suite -->
<xi:include href="file:///System/Library/ScriptingDefinitions/CocoaStandard.sdef" xpointer="xpointer(/dictionary/suite)"/>
<!-- specific suite(s) for the application follow... -->
<suite name="Simple Scripting Verbs" code="SVrb" description="Terminology for the SimpleScriptingVerbs Sample.">
<command name="do simple command" code="SVrbSimp" description="run a simple command with no parameters">
<cocoa class="SimpleCommand"/>
<result type="integer" description="returns the number seven"/>
</command>
</suite>
</dictionary>该命令的工作目标C实现如下:
@implementation SimpleCommand
/* This class implements a simple verb with no parameters. The verb
returns an integer number. Verbs don't get much simpler than this. */
- (id)performDefaultImplementation {
SLOG(@"SimpleCommand performDefaultImplementation");
/* return 7 to show how to return a number from a command */
return [NSNumber numberWithInt:7];
}
@end我试图将它移植到Monobjc是这样的:
using System;
using Monobjc;
using Monobjc.AppKit;
using Monobjc.Foundation;
namespace STest
{
[ObjectiveCClass]
public class SimpleCommand : NSScriptCommand
{
public SimpleCommand ()
{
}
public SimpleCommand(IntPtr nativePointer) : base(nativePointer)
{
}
[ObjectiveCMessage("performDefaultImplementation")]
public NSNumber performDefaultImplementation()
{
return NSNumber.NumberWithInteger (7);
}
}
}运行Applescript命令时
tell application "TheObjCVersion"
do simple command
end tell是否有可能在Mono应用程序中实现自定义脚本命令,如果有,如何实现?
发布于 2013-07-08 02:52:51
问题不在于.sdef或我的代码,而在于我的项目配置。我未能将.sdef设置为被复制,因此在运行时找不到它。
https://stackoverflow.com/questions/17517812
复制相似问题