首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >支持Mono应用程序中的应用

支持Mono应用程序中的应用
EN

Stack Overflow用户
提问于 2013-07-08 00:44:15
回答 1查看 284关注 0票数 1

编辑:我已经解决了这个问题;这是一个配置问题。确保您的.sdef是与您的应用程序一起复制/部署的,否则在运行时找不到它。

我正在使用Mono和Monobjc构建一个Mac应用程序,我希望能够通过AppleScript发送命令。我已经阅读了Apple文档,并获得了使用Objective的简单脚本动词示例,但我似乎无法将其翻译为使用Monobjc。内置命令如“退出”工作,但我在脚本定义中添加的命令的自定义套件在目标C版本中工作,但在单一版本中不能工作。正在使用的脚本定义是Stest.sdef:

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

代码语言:javascript
复制
@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是这样的:

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

代码语言:javascript
复制
tell application "TheObjCVersion"
    do simple command
end tell
  • 当我尝试使用Objective版本时,它会像您预期的那样返回7。
  • 当我尝试使用Mono版本时,它会抱怨编译器错误,将该命令中的“简单”标记为“行末修改,但找到标识符”。

是否有可能在Mono应用程序中实现自定义脚本命令,如果有,如何实现?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-08 02:52:51

问题不在于.sdef或我的代码,而在于我的项目配置。我未能将.sdef设置为被复制,因此在运行时找不到它。

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

https://stackoverflow.com/questions/17517812

复制
相关文章

相似问题

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