Sending a new iMessage fails with "Expected class name but found identifier"

Using the highly-rated answer from StackOverflow How to send an imessage text with applescript, only in provided service?:

on run {targetBuddyPhone, targetMessage}
    tell application "Messages"
        set targetService to 1st service whose service type = iMessage
        set targetBuddy to buddy targetBuddyPhone of targetService
        send targetMessage to targetBuddy
    end tell
end run

On Ventura, this errors at save with "Expected class name but found identifier." and highlights the first instance of "service". How should the script be corrected?

Is there a difference in grammar between releases? This code works on Big Sur.

Answered by DTS Engineer in 755164022

I’m not familiar with the backstory here, but on macOS 13 the class you’re looking for is called account, not service. So this code works:

tell application "Messages"
    set targetAccount to first account whose service type is iMessage
end tell

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

I’m not familiar with the backstory here, but on macOS 13 the class you’re looking for is called account, not service. So this code works:

tell application "Messages"
    set targetAccount to first account whose service type is iMessage
end tell

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Sending a new iMessage fails with "Expected class name but found identifier"
 
 
Q