My goal here is to apply the no break parameter of Illustrator with AppleScript to two words in a text frame.
I’m able to detect the non-breaking space in a string I want to apply to a text frame using:
ASCII character 202
Then I need to apply the no break parameter to the word after and before the character 202.
Currently, I’m trying a solution where I replace ASCII character 202 with ASCII character 175 (Ø) so then I can have the full word.
set ourText to "Hello my friend JonØDoe."
set findThis to (ASCII character 175)
set MW to words of ourText
repeat with aWord in MW
if findThis is in aWord then
set myWord to aWord
exit repeat
end if
end repeat
myWord
→ display: JonØDoe
Then I would like to search in the text frame for “JonØDoe” apply the no break parameter and replace Ø with a space which I haven’t achieved so far.
I tried manually in Illustrator, this would work.
Another solution not involving Ø would be to directly find the word preceding/succeeding the non breaking space but I haven’t been able to do that so far.
Hi. I had done something along these lines in InDesign a long time ago, when I first started messing around with AppleScript. “Word before” and “word after” are both valid objects. Specify an insertion point for each; i.e. get the beginning and end index values.
set findThis to ASCII character 202
tell application "Adobe Illustrator"'s document 1 to repeat with storyIndex from (count stories) to 1 by -1
tell story storyIndex to repeat with charIndex from (count characters) to 1 by -1
if character charIndex's contents is findThis then
tell (text from character (((word before character charIndex)'s character 1)'s index) to character (((word after character charIndex)'s character -1)'s index)) to set characters's no break to true
end if
end repeat
end repeat
I was out of pocket for several days and have just seen your feedback. Apparently, I didn’t actually use ASCII character 202 in my testing; it appears to be nothing more than a standard space, which is problematic as a target in a sentence. When using ASCII 175, the code can be adjusted so that the target references itself, which shortens and simplifies the code.
Concerning your last question, replacing all the content would naturally wipe the no break parameter—it’s a character style. The struck-through character you want to remove is already known by index, so it can be exchanged within the styled text. The below edit should yield the expected result.
set findThis to ASCII character 175
tell application "Adobe Illustrator"'s document 1 to repeat with storyIndex from 1 to (count stories)
tell story storyIndex to repeat with charIndex from (count characters) to 1 by -1
if character charIndex's contents is findThis then
set word after word before character charIndex's no break to true
set character charIndex's contents to space
end if
end repeat
end repeat