Copy link to clipboard
Copied
I am having an issue, that I really need to fix with my indesign script. Anytime I have an "&" in my changeTo string, the script is messing up, and replacing the text with an empty string. Do I need to do some sort of escape for the ampersand? I don't need to if I am not using a script, plus the ampersand is with quotes, so I am not understanding why this is breaking.
Any help would be GREATLY appreciated.
app.findTextPreferences = NothingEnum.NOTHING; | |
app.changeTextPreferences = NothingEnum.NOTHING; | |
app.findChangeTextOptions.caseSensitive = true; | |
app.findChangeTextOptions.includeFootnotes = false; | |
app.findChangeTextOptions.includeHiddenLayers = false; | |
app.findChangeTextOptions.includeLockedLayersForFind = false; | |
app.findChangeTextOptions.includeLockedStoriesForFind = false; | |
app.findChangeTextOptions.includeMasterPages = false; | |
app.findChangeTextOptions.wholeWord = false; | |
app.findTextPreferences.findWhat = "line 1"; | |
app.changeTextPreferences.changeTo = "R&T"; | |
doc.changeText(); | |
app.findTextPreferen |
Copy link to clipboard
Copied
your code works just fine for me, just doc.changeText(); changed to app.changeText();
no 'escapes’ for ampersand needed.
Copy link to clipboard
Copied
What is the difference between doc. and app., as I am only changing the text on the doc I have specified, would I not want to do the change at a document level?
I created some new scripts with the & in different positions in the string, and it appears to works fine, except on the one script that initially gave me the problem...strange...
Copy link to clipboard
Copied
Than you should define doc first, like this:
var doc = app.activeDocument;
Now your code might throw an error 'doc is not defined'
Copy link to clipboard
Copied
Oh, it is defined, I just didn't include it in the snippet I gave. Sorry about that. I changed around the page layout on the document after posting this question, and the 'glitch' doesn't seem to be happening anymore. I don't what I did, but the script is now working without changing the script.
Copy link to clipboard
Copied
Mr.Berzerk wrote
What is the difference between doc. and app., as I am only changing the text on the doc I have specified, would I not want to do the change at a document level?…
app.changeText() will change text for all open documents.
doc.changeText() will change text for the open document specified with variable doc.
You could even narrow the scope of your change action to let's say a story in your document. Or a range of text.
Scripting changeText() is more flexible than in the UI. E.g. there is no selected text needed to use changeText() on text.
Regards,
Uwe