This content has been marked as final. Show 3 replies
findWhat and changeTo expect the same syntax as in the UI, that is, regular text strings with special characters escaping and wildcarding the same way. A Forced Line Break in regular Find (findTextPreferences) is "^n" and in GREP mode "\n" (findGrepPreferences).
> Take notice of proper backslash escaping
That's it, thank you!
JS-"\r" works accidentally because Indesign treats this JS-generated line break the same way than the escape sequence backslash-r (written "\\r" in JS).
But "\n" has a different effect than "\\n" so your hint made my day.
app.changeGrepPreferences.changeTo = SpecialCharacters.FORCED_LINE_BREAK;
...won't work, because you don't enter a forced line break in the Find What field of the Find/Change panel. Instead, you enter a metacharacter--so you also use a metacharacter when you perform the task from scripting. This is what jongware's saying (thanks jongware!), but I thought I'd expand on it a bit.
In short: Don't use special characters enumerations in Find/Change. Sometimes, it'll work (when the characters are visible, non-control characters), sometimes it won't.