Copy link to clipboard
Copied
I'm replacing text from text frames within an illustrator file. Strings are pulled from an XML.
My problem is that the strings within the XML contain non-breaking spaces that are not carried over Illustrator when writing the text in the text frames.
Is there a way to write non-breaking spaces from AppleScript to text frames in Illustrator?
Thanks!
Copy link to clipboard
Copied
What if you put in unicode string "\u00a0" ?
Copy link to clipboard
Copied
Thanks for your reply!
I tried your suggestion but it just printed the string "\u00a0" in the text frame.
Before I also had tried and   but this just printed a regular space.
Copy link to clipboard
Copied
of course it wrote "& nbsp"
Copy link to clipboard
Copied
Using JS, it worked , but it really didn't put any space into the AI document, just had an effect of removing what was there in my text frame (I made a test to put in the string as contents of a line in my text frame). So, maybe you can just replace the non-breaking spaces with regular spaces?
Copy link to clipboard
Copied
I use the following in AppleScript:
set the contents of textFrame to myText
Hmm, I'm not sure if I understand. I don't know if I was clear with what I wanna do; I would like to use the non-breaking space to keep 2 words together (like names: Bill Gates; I don't want to have Bill on a line and Gates on another line) even tho we are at the end of the width of the text frame, it should put the 2 words on the next line.
Copy link to clipboard
Copied
I see what you mean, and according to this thread, the prospects are grim. Maybe, using the text commands you can apply a no-break attribute to the text range like the thread claims.
Copy link to clipboard
Copied
Yes, I see it's in characterAttributes - bool noBreak.
Well, that just kind of sucks, having this new obstacle in you otherwise seemingly straightforward workflow. At least, since scripting is used you can apply that character attribute to text with more lines of code than you certainly planned on writing at first.
Copy link to clipboard
Copied
Hmmm, I tried detecting the non break spaces within the XML by searching the ASCII characters 255 (noBreak ASCII char), to then apply to this character the property noBreak.
However, it doesn't find any ASCII character 255, any idea what I could be doing wrong?
set search to (ASCII character 255)
set AppleScript's text item delimiters to search
set textItems to the text items of (input as text)
Copy link to clipboard
Copied
I don't know, can you make it search for UTF character \u00a0 ?
Copy link to clipboard
Copied
I don't why but I found out AppleScript detects non-breaking space as ASCII character 202 and not 255 as it should be?
My next step is to try to apply the noBreak parameter to the word before and the word after the non breaking space!