Sending messages from terminal

Hi everyone,
after update to Big Sur my script for sending messages stops to work.
I have the error in Polish
"execution error: Messages — błąd: Nieprawidłowy format klucza. (-10002)"
probably in english is something like:
execution error: Messages — error: bad format of key. (-10002)

The scriot is very simple:

on run {phoneNumber, message}
tell application "Messages"
send message to buddy phoneNumber of service "SMS"
end tell
end run

Please help :)
Messages got a significant rewrite in macOS 11 and it’s not uncommon for that to cause problems for the AppleScript support. Regardless of what else you do, you should file a bug about this so that the Messages engineering team can investigate. Make sure to include a copy of the script that reproduces the problem.

Please post your bug number, just for the record.

Does this problem reproduce if you run the script from Script Editor? If so, try breaking it up into parts to see if you can work out what specific item it’s complaining about. For example, does service "SMS" work? What about buddy phoneNumber of service "SMS"?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
I was able to fix mine by removing the "of service "SMS" line

on run {phoneNumber, message}
  tell application "Messages"
   send message to buddy phoneNumber --of service "SMS"
  end tell
end run
Hi,
Thanks for help but now the messages are send as iMessage - they are blu and not green and not going to persons without iPhone.
So how to force using sms?

 send message to buddy phoneNumber --of service "SMS" this line not produce any error in terminal but messages are going as imessages not as sms

Please help
I have this same issue, and same code, but removing of service "SMS" did not solve my problem.
script editor edits the code automatically on run to this:

on run {targetBuddyPhone, targetMessage}
tell application "Messages"
send targetMessage to participant phoneNumber of account "SMS"
end tell
end run



I SOLVED IT! This code works.

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

on run {phoneNumber, message}
tell application "Messages"
activate
send message to buddy phoneNumber of service 2 --1 =imessage, 2=SMS, did not try other numbers
end tell
end run
Does anyone know how to generalize the code so that you can either send messages (blue iMessages) to recipients who have iMessages, and if recipients have an android device we can then and only then send us a text message (green sms) without having to have two separate scripts (i.e. 9 one for iMessages and one for SMS messages)
Sending messages from terminal
 
 
Q