Keystroke bug with non-breaking-space character 8239

Heads up on a bug in the keystroke command:

If there is a Unicode “narrow no-break space” (8239) in a string, and you use keystroke to type that string somewhere (tested in Terminal and TextEdit, so probably anywhere), that character gets replaced by the character “a”.

Here is sample code to replicate this:

set myString to "Screen Recording 2025-12-16 at 5.54.04 PM.mov"

tell application "TextEdit"
	activate
	make new document
	delay 0.5
end tell
-- Type in the string:
tell application "System Events"
	keystroke myString
	delay 0.5
end tell

When I run this, the end of the file name is “5.54.04aPM.mov” (notice the extraneous “a”), instead of “5.54.04 PM.mov”.
That’s because apparently macOS saves the “time” in the names of screen shots and screen recordings using a non-breaking space before the AM/PM.

Anyone know why keystroke is unable to type that perfectly-valid-if-sneaky Unicode character?
I can set the clipboard and then paste, but I’d love to avoid modifying the clipboard, if possible.

That has been around since at least Sonoma. Looks like the forum ate the NNBSP in your sample script, by the way.

I think it was put in there to prevent a line break between the time and “AM/PM”, but obviously something didn’t get the message. As far as I can tell, it only happens with keystroke and not writing as «class utf8».

I was wondering if there might be a non-breaking space in the locale time settings.

You could always substitute with it as a workaround.

set mys to "Screen Recording 2025-12-16 at 5.54.04 PM.mov"
set text item delimiters to {space, character id 160}
set mys to text items of mys as text