• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Text replace with an ampersand "&" 2015 indesign script

Community Beginner ,
Aug 10, 2017 Aug 10, 2017

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
TOPICS
Scripting

Views

609

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Aug 10, 2017 Aug 10, 2017

Copy link to clipboard

Copied

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

no 'escapes’ for ampersand needed.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 10, 2017 Aug 10, 2017

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Aug 10, 2017 Aug 10, 2017

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'

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 10, 2017 Aug 10, 2017

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 11, 2017 Aug 11, 2017

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines