2

I get the error: Can’t get service of text chat id "iMessage;-;". (-1728) - when trying to send a text to another imessage client on a mac (different user). Here is the code fragment where it is failing:

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.

4

2 回答 2

1

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

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

在查看messages.app的字典时,似乎没有聊天“服务”,但有好友。

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

因为我可以从“伙伴”那里获得服务,所以我不需要 mklement0 的回答(但我非常感谢您的回答)所以我暂时保持原样。

于 2015-12-11T17:52:40.840 回答
0

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

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

注意:message received事件的for参数(theChat在 OP 的代码中)是text chat类的一个实例,它继chat承自基类。如果脚本编辑器中的字典查看器未配置为显示继承text chat的项目,则通过查看它确实具有 - 当前有问题的 -service属性的类将不会很明显。要使继承的项目可见,请打开脚本编辑器的首选项对话框并选中Show inherited items.


AppleScript 支持中似乎存在一个错误Messages.app(在 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))
于 2015-12-10T03:02:20.223 回答