将数据发送到另一个应用程序并从中获取响应

Raj*_*lak 5 macos nsappleeventdescriptor swift

我正在尝试相互交流应用程序。

我正在使用第一个应用程序处理Apple Events

NSAppleEventManager.shared().setEventHandler(self, andSelector: #selector(handleGetURLEvent), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))

func handleGetURLEvent(_ event: NSAppleEventDescriptor, withReplyEvent replyEvent: NSAppleEventDescriptor)
Run Code Online (Sandbox Code Playgroud)

在第二个应用程序中,我正在创建NSAppleEventDescriptor对象

let test = NSAppleEventDescriptor(string: "test")
let descriptor = NSAppleEventDescriptor(eventClass: AEEventClass(kInternetEventClass), eventID: AEEventID(kAEGetURL), targetDescriptor: nil, returnID: AEReturnID(kAutoGenerateReturnID), transactionID: AETransactionID(kAnyTransactionID))
descriptor.setParam(test, forKeyword: keyDirectObject)
Run Code Online (Sandbox Code Playgroud)

现在,NSWorkspace我启动了我的第一个应用程序

NSWorkspace.shared().launchApplication(at: myAppUrl, options: .default, configuration: [NSWorkspaceLaunchConfigurationAppleEvent:descriptor])
Run Code Online (Sandbox Code Playgroud)

一切都OK了,函数handleGetURLEvent被调用,但是... replyEvent.desciptorTypekAENullEvent我也没有线索,我怎么会得到你replyEvent在我的第二个应用程序。

我想这种解决方案有问题。

所以我的问题是,我怎样才能简单地将数据发送到其他应用程序并取回一些数据?