正在尝试从带有applescript的os x消息接收消息

正在尝试从带有applescript的os x消息接收消息,applescript,messages,ichat,Applescript,Messages,Ichat,嘿,我正在运行以下脚本: using terms from application "Messages" on message received this_message from this_buddy for this_chat display dialog "test" end message received end using terms from 但每次收到消息时,我都会在消息中出现以下错误: Event: Message Received in Ac

嘿,我正在运行以下脚本:

using terms from application "Messages"
    on message received this_message from this_buddy for this_chat
        display dialog "test"
    end message received
end using terms from
但每次收到消息时,我都会在消息中出现以下错误:

Event: Message Received in Active Chat
File: registerToReceiveMessages.applescript
Error: Error -1708
我在网上的任何地方都找不到那个错误。它似乎适用于除活动聊天之外的所有聊天。有什么想法吗

此外,我还尝试为收到的已寻址消息添加事件,但每次编译applescript时,都会将其替换为收到的远程屏幕共享邀请

在我看来,message received事件处理程序只有在消息中感觉到它时才起作用。我有一个稍微不同的脚本相同的问题。在另一个网站上找到另一个示例后,将其复制粘贴到新的AppleScript编辑器窗口中,并将其保存在通过消息复制到~/Library/Scripts/Messages的AppleScript文件上,它开始工作

您的脚本似乎没有问题。如果我用您的代码替换当前脚本并保存脚本,它将按预期工作,显示包含文本测试的对话框

只需将脚本设置为“无”并返回到您在“消息设置”中创建的脚本即可。

只要您选择了不处理指定事件的AppleScript,就会出现错误-1708

例如,若您的脚本仅在发送的消息上实现,但您将此脚本设置为每次收到消息时运行,则会出现错误-1708。这是因为您的脚本只知道如何处理传出消息,而不知道如何处理传入消息,因此出现错误-1708

现在有一些有趣的事情

如果您尝试使用默认脚本Mix Message Case.applescript处理接收的事件消息、活动聊天中接收的消息和发送的消息。第一次和最后一次都可以正常工作,但是对于活动聊天事件,您将得到一个-1708错误。我们可以推断,这意味着脚本没有处理活动聊天中接收到的事件消息。因此,现在看来,即使是苹果也无法应对这一事件

OS X Mavericks更新:

此更新修复了前面提到的错误。如果选择Apple的示例脚本Speak Events.applescript,您会注意到它完美地处理了活动聊天室收到的消息。如果检查代码,您会注意到它正在使用on active chat message received方法。我们现在可以在脚本中使用它。由于我不再安装旧版本,因此无法测试此方法是否适用于以前的版本

以下是Speak Events.applescript中的代码:

on active chat message received with eventDescription
    say eventDescription
end active chat message received
还请注意,您不再指定要为特定事件运行的单个脚本。相反,您可以为消息事件指定单个脚本处理程序。这意味着您必须实现所有事件,以避免获取-1708方法。请注意,在示例脚本中,Apple甚至有以下注释:未使用,但需要定义以避免错误。以下是一个模板,可以用作脚本的起点:

using terms from application "Messages"
    # The following are unused but need to be defined to avoid an error

    on message sent theMessage with eventDescription
    end message sent

    on message received theMessage with eventDescription
    end message received

    on chat room message received with eventDescription
    end chat room message received

    on active chat message received with eventDescription
    end active chat message received

    on addressed message received theMessage from theBuddy for theChat with eventDescription
    end addressed message received

    on received text invitation with eventDescription
    end received text invitation

    on received audio invitation theText from theBuddy for theChat with eventDescription
    end received audio invitation

    on received video invitation theText from theBuddy for theChat with eventDescription
    end received video invitation

    on received local screen sharing invitation from theBuddy for theChat with eventDescription
    end received local screen sharing invitation

    on buddy authorization requested with eventDescription
    end buddy authorization requested

    on addressed chat room message received with eventDescription
    end addressed chat room message received

    on received remote screen sharing invitation with eventDescription
    end received remote screen sharing invitation

    on login finished with eventDescription
    end login finished

    on logout finished with eventDescription
    end logout finished

    on buddy became available with eventDescription
    end buddy became available

    on buddy became unavailable with eventDescription
    end buddy became unavailable

    on received file transfer invitation theFileTransfer with eventDescription
    end received file transfer invitation

    on av chat started with eventDescription
    end av chat started

    on av chat ended with eventDescription
    end av chat ended

    on completed file transfer with eventDescription
    end completed file transfer

end using terms from

如果您从这个脚本开始,只实现您需要的方法,而其余的保持不变,那么您应该避免所有-1708错误。

您曾经解决过这个问题吗?哈哈,这里也有同样的问题。AppleScript,一种具有如此现代概念的语言,但错误消息让你想起了20世纪80年代!错误为未处理事件,但我找不到活动聊天中收到的消息的事件