AppleScript: Error -1728 "Messages got an error: Can’t get service of item 1 of every text chat."

Ive been working on a script to automatically rejoin Jabber based MUC rooms from messages. This script worked flawlessly up until trying on El Cap beta. After digging around and trying some very basic functions it appears that the scripting language for Messages is broken. Here is the code that currently works in Yosemite and not in El Cap.


repeat

with timeout of 3600 seconds

if application "Messages" is running then

tell application "System Events" to tell process "Messages"

with timeout of 3600 seconds

set AllWindows to name of every window

if (AllWindows contains "Verify Certificate") then

perform action "AXRaise" of (first window whose name contains "Verify Certificate")

click button "Continue" of group 2 of window "Verify Certificate"

display notification "I DID THE THING!" with title "Verify Certificate Alert Exterminated"

end if

end timeout

end tell

tell application "Messages"

with timeout of 3600 seconds

repeat with c in text chats

if connection status of service of c is connected and join state of c is not joined and (name of c ends with "@test.chatdomain.com" or name of c ends with "@test.chatdomaintwo.com") then

accept c

display notification "Jabber chatrooms have been rejoined" with title "I DID THE THING!"

end if

end repeat

end timeout

end tell

end if

delay 20

end timeout

end repeat


Other basic commands Ive tested are:


tell application "Messages"


accept text chat "test@test.im.com"


end tell


Ive replaced the specific group chat name in the above code for privacy reasons. The basic code returns an error:

"Messages got an error: text chat \"test@test.im.com\" doesn’t understand the “accept” message."


What am I missing here?

Does Shift+Cmd+O > Open Messages Dictionary > Search for "accept" tell you anything you don't already know?

I'd check it myself but my computer with the 10.11 partition is busy doing something in Yosemite atm.

Unfortunately not, that was actually where I found the information to test the basic script. I honestly didnt know the libraries even existed until I ran into a problem with this script and did some deep diving haha.


The accept entry looks like this:

accept v : Accepts an incoming text, audio, or video chat invitation, or file transfer

accept chat or file transfer

Based on the dictionary current to the new release of 10.10.4, it appears to me that only the chat class responds to the accept command; the text chat class doesn't seem to (it only responds to send).

The dictionary actually looks identical to 10.10.4 from what I can tell, however using just:


tell application "Messages"


accept chat "test@test.im.com"


end tell


Returns the same error.

hmmm... Actually text chat should inherit properties from chat anyway - whether it should also inherit responses too, I'm not sure. Your script works on my 10.10.4 - but you already know that...


But where text chat is identified by name, chat is identified by id. What does:


tell application "Messages" to accept item 1 in chats

and

tell application "Messages" to return connection status of service of item 1 in chats


yield?

Neither of the above are problematic on 10.10.4 (the second returns "connected").


If they are problematic on 10.11 DP2 then it could be a case of having to resign to the fact that some of this sort of functionality is missing in early Developer Previews.

tellapplication "Messages" toreturn connection status ofserviceofitem 1 ofchats

returns:

error "Messages got an error: Can’t get service of item 1 of every chat." number -1728 from serviceofitem 1 ofeverychat

tell application "Messages" to accept item 1 in chats

returns:

error "Messages got an error: item 1 of every chat doesn’t understand the “accept” message." number -1708 from item 1 of every chat

Hopefully it is just something that is still in transition. Ive got this tool in use by over 2000 people so Im trying to stay ahead of any issues in the next OS update to minimize downtime. Thank you for the suggestions though, I really appreciate the input!

Happy to look into it with you 🙂


Interestingly, when I pass the wrong text chat id (see examples below) I get the same error messages as you. Just to rule out the possibility of there being a problem with the every command (clearly in operation once Script Editor resolves the "sentence" into applicable slightly-lower-level-language chunks, and it keeps appearing in error messages), it might just be worth getting the result of:


tell application "Messages" to return item 1 in chats


(If even that returns an error then that would throw the every command into suspicion straight off the bat) and then use the output (in my case text chat id "iMessage;-;xxxxxxxxxxx@xxxxx.***" of application "Messages") to explicitly indicate a specific chat as follows:


tell application "Messages" to accept text chat id "iMessage;-;xxxxxxxxxxx@xxxxx.***" of application "Messages"

and

tell application "Messages" to accept chat id "iMessage;-;xxxxxxxxxxx@xxxxx.***" of application "Messages"


or


tell application "Messages" to return connection status of service of text chat id "iMessage;-;xxxxxxxxxxx@xxxxx.***" of application "Messages"

and

tell application "Messages" to return connection status of service of chat id "iMessage;-;xxxxxxxxxxx@xxxxx.***" of application "Messages"

Getting closer

tell application "Messages" to return item 51 in chats

Returned: text chat id "Jabber;#;XXXX@muc.XXXX.com" of application "Messages"


I then tried

tell application "Messages" to accept text chat "Jabber;#;XXXX@muc.XXXX.com"

and

tell application "Messages" to accept text chat "Jabber;#;XXXX@muc.XXXX.com" of application "Messages"

and

tell application "Messages" to return connection status of service of chat id "Jabber;#;XXXX@muc.XXXX.com" of application "Messages"


Getting errors -1708 still. Also it looks like "tell application "Messages" to return item 51 in chats" gives the same result on both El Cap and Yosemite.

I notice that you omitted id after text chat in your tests. It may not matter but you never know....

I just booted into 10.11 and ran


tell application "Messages" to return properties of every chat


and got:

{{class:item}}


So chat, text chat, etc. are completely devoid of all the properties that they're meant to have. Can only hope they reappear down the line.


Best of luck with the tool.

AppleScript: Error -1728 "Messages got an error: Can’t get service of item 1 of every text chat."
 
 
Q