在安装OS X的JavaScript自动化事件侦听器(JXA) [英] Attach event listeners in OS X JavaScript for Automation (JXA)

查看:306
本文介绍了在安装OS X的JavaScript自动化事件侦听器(JXA)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这怎么可能侦听在OS X中的JavaScript事件自动化。

How is it possible to listen for events in OS X JavaScript for automation.

在脚本库的消息应用程序存在的事件处理程序,如 messageSent 的messageReceived 列表。不过,我可以不知道如何使用它们。试图通过一个函数产生一个错误,并试图将这些变量设定为新的功能会导致REPL挂起。

In the scripting Library for the Messages application there is a list of event handlers, such as messageSent and messageReceived. However, I cannot figure out how to use them. Trying to pass a function yields an error, and trying to set these variables to new functions causes the REPL to hang.

什么是设置这些事件处理程序的正确方法?

What is the proper way to set up these event handlers?

推荐答案

您将创建一个脚本,您再从AppleScript的处理程序菜单中选择 preferences>常规。使用内置的在线Events.applescript 文件作为指导,要知道,你必须覆盖每一个处理程序,它正确执行。

You would create a script that you then select from the AppleScript handler menu in Preferences > General. Use the built-in Speak Events.applescript file as your guide and be aware that you have to override every single handler for it to execute properly.

注意:即使加标在内,你仍然不能称之为像脚本除了命令说()有可能是由于他们是如何实现的此层上的脚本引擎之上,使得使用 currentApplication()甚至适当的呼叫看起来好像正在发送跨应用程序。

Note: even with Standard Additions included, you still cannot call scripting addition commands like say() likely due to how they've implemented this layer on top of the scripting engine, making even an appropriate call using currentApplication() look as if it is being sent cross-application.

下面是一个模板:

Messages = Application.currentApplication()
Messages.includeStandardAdditions = true

function messageSent(m, e) {
}

function messageReceived(m, e) {
}

function chatRoomMessageReceived(e) {
}

function activeChatMessageReceived(m, e) {
}

function addressedMessageReceived(m, b, c, e) {
}

function receivedTextInvitation(e) {
}

function receivedAudioInvitation(m, b, c, e) {
}

function receivedVideoInvitation(m, b, c, e) {
}

function receivedLocalScreenSharingInvitation(b, c, e) {
}

function buddyAuthorizationRequested(e) {
}

function addressedChatRoomMessageReceived(e) {
}

function receivedRemoteScreenSharingInvitation(e) {
}

function loginFinished(e) {
}

function logoutFinished(e) {
}

function buddyBecameAvailable(e) {
}

function buddyBecameUnavailable(e) {
}

function receivedFileTransferInvitation(e) {
}

function avChatStarted(e) {
}

function avChatEnded(e) {
}

function completedFileTransfer(e) {
}

这篇关于在安装OS X的JavaScript自动化事件侦听器(JXA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆