값을 얻기 위해 Swift 응용 프로그램을 호출하는 AppleScript를 작성하려고합니다. 이 메서드는 문자열을 사용하고 다른 문자열을 반환해야합니다.AppleScript에서 Swift 메서드 호출
<suite name="My Suite" code="MySU" description="My AppleScript suite.">
<class name="application" code="capp" description="An application's top level scripting object.">
<cocoa class="NSApplication"/>
<element type="my types" access="r">
<cocoa key="types"/>
</element>
</class>
<command name="my command" code="MyCOMMND" description="My Command">
<parameter name="with" code="MyPR" description="my Parameter" type="text">
<cocoa key="myParameter"/>
</parameter>
<result type="text" description="the return value"/>
<cocoa method="myCommand:"/>
</command>
</suite>
해당 스위프트 코드는 매우 간단하다 :
func myCommand(_ command: NSScriptCommand) -> String
{
if let myParameter = command.evaluatedArguments?["myParameter"] as? String
{
return "Hello World!"
}
else
{
return "Nothing happening here. Move on."
}
}
그리고 마지막으로 내 애플 스크립트가 여기에 있습니다 : 여기
나의하여 .sdf 파일입니다tell application "MyApp"
set r to my command with "Hello"
end tell
내가 실행 AppleScript는 내 명령을 인식하지만, 내가 연관 시키려 던 Swift 코드를 호출하지 않습니다. Xcode 또는 AppleScript는 문제를보고하지 않습니다. 내가 놓친 것을 놓치거나 내 코드를 틀린 장소에 두 었는가?
'name ="my command "'my는 AppleScript 키워드이므로, 이름의 일부로 사용하지 말 것을 권합니다. 그다지 좋지는 않습니다. – matt