2013-07-08 1 views
1

편집 :이 문제를 해결했습니다. 구성상의 문제였습니다. .sdef가 앱과 함께 복사/배포되었는지 확인하십시오. 그렇지 않으면 런타임에 찾을 수 없습니다.모노 응용 프로그램에서 AppleScript로 작성

Mono와 Monobjc를 사용하여 Mac 응용 프로그램을 만들고 있는데 AppleScript로 명령을 보내고 싶습니다. Apple 설명서를 읽고 Objective C를 사용하여 작동하는 Simple Scripting Verbs 예제를 얻었지만 Monobjc와 함께 작동하도록 번역 할 수는 없습니다. "quit"과 같은 내장 명령은 작동하지만 스크립팅 정의에 추가하는 명령이있는 사용자 정의 제품군은 Objective C 버전에서 작동하지만 모노 버전에서는 작동하지 않습니다.

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); 
     } 
    } 

} 
:

@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에 포트이 내 시도는 이것이다 :

<?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 구현이 있습니다 : 사용되는 스크립트 정의는 Stest.sdef입니다

AppleScript 명령을 실행할 때

tell application "TheObjCVersion" 
    do simple command 
end tell 
  • Objective-C 버전을 사용해 보았을 때 예상대로 7을 반환합니다.
  • 모노 버전으로 시도 할 때 컴파일러 오류가 발생하여 "xpected end of line. 그러나 식별자를 찾았습니다."라는 명령의 "simple"플래그가 표시됩니다.

Mono 응용 프로그램에서 사용자 지정 스크립팅 명령을 구현할 수 있습니까? 그렇다면 어떻게해야합니까?

답변

1

문제는 .sdef 또는 코드와 관련이 없으며 프로젝트 구성과 관련이 있습니다. .sdef를 복사 할 수 없으므로 런타임에 찾을 수 없습니다.

+1

답장을 수락하기 위해 2 일 후에 돌아 오는 것을 잊지 마십시오 (http://blog.stackoverflow.com/2009/01/accept-your-own-answers/). –