Send Message To Recipient Whose Name Contains An Emoji

Problem

Can anyone tell me why using an emoji in a message recipient name fails?
I do have an existing Message recipient, a group of three people; its original name was changed to match an iOS group.

Meta

Messages 11.0
macOS 10.13.6

Script

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
--
set moneybag_cp_dec to 128176
set moneybag_char to character id moneybag_cp_dec
set recipient_name to "Weekly NFL Picks"
set recipient to moneybag_char & recipient_name & moneybag_char
set message to "
NFL 2025 Week 8 Games
-----------------------------------
Commanders @ Chiefs
Vikings @ Chargers
Dolphins @ Falcons
Jets @ Bengals
Browns @ Patriots
Giants @ Eagles
Bills @ Panthers
Bears @ Ravens
49ers @ Texans
Buccaneers @ Saints
Cowboys @ Broncos
Titans @ Colts
Packers @ Steelers
"
tell application "Messages"
    activate
    display dialog "Recipient: " & recipient giving up after 5
    try
        send message to buddy recipient  -- 'text chat' didn't work
    on error errMessage number errNum
        display dialog errMessage & return & errNum
    end try
end tell

Dialog Output

Messages got an error: Can’t get buddy “:moneybag:Weekly NFL Picks​:moneybag:”.
-1728

Three things:

First, to format your code for posting, please put three backticks (the key above the tab) on a line immediately above and below your code. Don’t include any other characters. This will make it easier to read as well as copy your text. Thanks.

```
[your code here]

```

Second, this is just a stab at the problem as I don’t use this app.

The -1728 error means that the item in question doesn’t exist where it is being requested from. So there is probably a missing piece to this line:

`send message to buddy recipient`

The dictionary for my version —which is old— suggests that you need to also specify either the service or text chat. The service you’re using needs to be figured out and specified. Perhaps something like this:

set bestBuddy to participant littleBuddy of account id targetedService
   

Whatever would be appropriate in your case, there should be an ‘of’ followed by whatever. And if it’s a text chat, then likely it would have a number as well, eg text chat 1.

Third: Regarding the emoji… it seems strange that it gets the first one correct but not the last one. Are you able to send to someone whose recipient name does not include any emoji?

1 Like

I can’t explain it well in English, but maybe it’s like this?

use AppleScript version "2.4"
use scripting additions


set moneybag_cp_dec to 128176 as integer
set moneybag_char to (character id moneybag_cp_dec) as text
set recipient_name to "Weekly NFL Picks" as text


log class of moneybag_char & recipient_name & moneybag_char
-->{text, "Weekly NFL Picks", "💰"}
--> {class of 💰 , "Weekly NFL Picks" , 💰}
-->NOTE: Text is undefined here, resulting in a value class of 'list'."

log class of (moneybag_char & recipient_name & moneybag_char) as text
-->(*text*)


check name of every participant

use AppleScript version "2.4"
use scripting additions

tell application "Messages"
	set listAddName to (name of every participant) as list
end tell
log listAddName
-->I think the name is not listed here?

set valueResponse to (choose from list listAddName)
set strRecipient to (first item of valueResponse) as text
log strRecipient


set recipient to moneybag_char & recipient_name & moneybag_char
-->check recipient


  1. Sorry about the code formatting – I noticed it was fubar when I posted it, but forgot the GitHub code block aspect. Figured I’d figure out how to fix it when it wasn’t 4am.

  2. Using your ‘text chat 1’ approach posted to a random account from years ago.

  3. Yes, if I change recipient to just my name, the code works like a champ.
    I did notice one thing examining that particular field in SD7 – it looks as expected for the “Best” and “Source” views. But the “AEPrint” view shows 'utxt'("?Weekly NFL Picks?") which would explain the failure. But surely AS 2.7 is using Unicode, no?

Saw somewhere else the font cache data might be botched.
Could attempt fixing this using $ sudo atsutil database -remove and rebooting, but that seems rather drastic.

Regarding:

  1. The code looks better now. Thanks for editing it.

  2. ‘1’ is just an example. The issue is that you must specify an account and a service/chat in some manner. It could be an index number or a name or maybe an ID. So you need to try and find out how to specify the desired text chat.

I’ll use the Finder for an example because I don’t use Messages. Each of these statements refers to the exact same window.

tell application "Finder"
	position of Finder window 1
	--> {0, 204}

	position of Finder window "Desktop"
	--> {0, 204}

	position of window id 40509
	--> {0, 204}
end tell

You can get a list of all Finder windows this way:

	Finder windows
	--> {Finder window id 40509 of application "Finder", Finder window id 40985 of application "Finder", Finder window id 40103 of application "Finder"}

So maybe try something similar by itself inside a Messages tell block:

    text chats

This might return all of the text chats. Or maybe even this:

    text chat -1

or

    last text chat
  1. Yes. Unicode has been supported since OS X began. Applescript became ‘entirely unicode-based’ in AS 2.0 (OS X 10.5 Leopard).

That said, I think it might be a unicode issue, but not one that’s specific to applescript.

The unicode for the character is:

Unicode: U+1F4B0, UTF-8: F0 9F 92 B0

So it needs 4 bytes. Not sure whether there are any font-related issues.

FWIW I get some odd behaviour. I can’t paste the character anywhere. I have to go into the ‘show emoji and symbols’ tool to enter it. And textedit pops up an alert warning that it cannot auto-save the document.

Dunno whether my system will act differently after a reboot but right now it’s choking on the character.

It’s a mystery. And yes, that does seem drastic.