AppleScript for iMessage出错 - 无法获得文本聊天ID服务

时间:2015-12-09 04:45:01

标签: applescript imessage

我收到错误:无法获得文本聊天ID服务“iMessage; - ;”。 (-1728) - 尝试将文本发送到mac(不同用户)上的另一个imessage客户端时。这是失败的代码片段:

using terms from application "Messages"
    on message received theText from theBuddy for theChat
        # get what we need
        set recvService to name of service of theChat

THX。

2 个答案:

答案 0 :(得分:1)

好的,只是更新,也许是解释(?):

set recvService to name of service of theChat - fails.
set recvService to name of service of theBuddy - works.

在查看messages.app的字典时,似乎没有" service"聊天,但有伙伴。

我只是开始在El Capitan编写脚本,所以我不知道这是改变还是错误。我会将其留给更有经验的人来评论。

由于我可以从" buddy"获得服务,我不需要mklement0的回答(但我非常感谢回复)所以我&#39 ;现在就把事情保留原样。

答案 1 :(得分:0)

更新:如下所述,观察到的行为是错误。但是,OP自己找到了一种解决方法:from事件的message received参数(示例代码中为theBuddy)是Buddy类的一个实例,其中 还有一个service属性,它可以正常运行:

set recvService to name of service of theBuddy # instead of the buggy `of theChat`

注意:message received事件的for参数(OP代码中的theChat)是text chat的一个实例class,继承自chat基类。如果脚本编辑器中的字典查看器未配置为显示继承的项目,那么通过查看它确实具有的text chat类 - 当前有错误 - 将不会显而易见 - service财产。要使继承的项目可见,请打开“脚本编辑器”的“首选项”对话框,然后选中Show inherited items

Messages.app的AppleScript支持中出现了这一错误(在OSX 10.11.1上观察到);我建议你在http://bugreport.apple.com提交一个错误;这是一个简单的演示:

tell application "Messages"

    set svc to first item of services

    set cht to first item of (chats of svc)

    # !! Breaks, even though it should return the same object as `svc`.
    # "Can’t get service of text chat id \"iMessage;-;<recipient>\"."
    service of cht 

end tell

似乎尝试访问text chat实例的任何属性目前已被破坏。

您可以尝试解决方法:

# Given a chat instance, returns its originating service.
on getService(cht)
    local svc, cht
    tell application "Messages"
        repeat with svc in services
            try
                (first chat of svc whose it is cht)
                return contents of svc
            end try
        end repeat
    end tell
    return missing value
end getService

# Sample invocation
set recvService to name of (my getService(theChat))
相关问题