Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何翻译';使用来自…';到OSA事件处理程序中的Javascript_Javascript_Macos_Event Handling_Osascript - Fatal编程技术网

如何翻译';使用来自…';到OSA事件处理程序中的Javascript

如何翻译';使用来自…';到OSA事件处理程序中的Javascript,javascript,macos,event-handling,osascript,Javascript,Macos,Event Handling,Osascript,我想使用osascript命令调用一些JavaScript代码。该代码应一直运行,直到收到来自消息的聊天消息。最后,我打算从节点执行此操作,并接收回聊天消息、发件人等 我能够编译一个“保持运行”的JavaScript应用程序,并通过 osascript -l JavaScript JSiMessageReceiver.app 其中JSiMessageReceiver.app function run() { var Messages = Application('Messages');

我想使用osascript命令调用一些JavaScript代码。该代码应一直运行,直到收到来自消息的聊天消息。最后,我打算从节点执行此操作,并接收回聊天消息、发件人等

我能够编译一个“保持运行”的JavaScript应用程序,并通过

osascript -l JavaScript JSiMessageReceiver.app
其中JSiMessageReceiver.app

function run() {
    var Messages = Application('Messages');
    Messages.includeStandardAdditions = true;
    console.log('started');
}

function quit() { // should prevent app from quitting
    return true;  // according to Apple's developer release notes
}

function messageReceived(text) {
    console.log('message received: ' + text);
}
当然,永远不会调用
messageReceived
处理程序,因为它尚未与消息关联。在AppleScript中,这是通过

using terms from application "Messages"
    on message received theMessage from theBuddy for theChat
        processMessage("message received", theMessage, theBuddy, theChat)
    end message received
end using terms from
如何将其转换为JavaScript?我没有找到任何关于这方面的文件。
有什么想法吗?

在JavaScript上试试这个:

function messageReceived(theMessage, eventDescription) {
    processMessage("message received", theMessage,
                    eventDescription.from, eventDescription.for);
}
请参见
AppleScript编辑器
-
菜单窗口>库
-
消息事件处理程序套件
中的messageReceived函数的事件描述。
其中的工作示例如下: