Skip to main content
Mr_Berzerk
Participant
August 10, 2017
Question

Text replace with an ampersand "&" 2015 indesign script

  • August 10, 2017
  • 1 reply
  • 860 views

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
This topic has been closed for replies.

1 reply

winterm
Legend
August 10, 2017

your code works just fine for me, just doc.changeText(); changed to app.changeText();

no 'escapes’ for ampersand needed.

Mr_Berzerk
Participant
August 10, 2017

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...

winterm
Legend
August 10, 2017

Than you should define doc first, like this:

var doc = app.activeDocument;

Now your code might throw an error 'doc is not defined'