-1

I am just looking for a simple javascript that replaces the selected copy with the user specified copy or the one that could be inserted into the script as string in Adobe Indesign. googled it for several hours, but could not find an answer.

Example:- I was born on August. I just want to change the text "August" to "September" by selecting and running the javascript. do not want to do manually because it needs to be changed across several documents. at the same time I dont want the script to change everything without my knowledge, just want to change one document & one selection at a time.

  • Possible duplicate of [How to replace all occurrences of a string in JavaScript?](https://stackoverflow.com/questions/1144783/how-to-replace-all-occurrences-of-a-string-in-javascript) – MathKimRobin Jan 07 '18 at 12:15
  • @MathRobin: for a pure Javascript string: yes. But changing text inside an InDesign document needs interacting with its DOM. – Jongware Jan 07 '18 at 15:51

4 Answers4

0

There is Find / Change in Edit menu that can do the same for you without scripting. You might want to give that a try. Simply "Find" the instances you want to replace. Then "Change/Find" will replace it and move to the next instance. Simple "Replace" with just replace the instance and stays there instead of moving to next instance.

  • Hi, thanks for your reply. But I need a script because the copy that needs to be changed differs across all the documents while the replacement copy stays the same. – Raja Sundaram Jan 03 '18 at 19:28
0

How much differ? If just a few - still may use Find/Change (tab 'Grep')

Something like Find: (1stMatch)|(2ndMatch)|(3rdMatch)

Cashmirek
  • 269
  • 1
  • 9
0

You should just use String.replace method.

Like this :

var yourString = "I was born on August."
yourString = yourString.replace('August', 'September');
MathKimRobin
  • 1,268
  • 3
  • 21
  • 52
0

This is trivial. Select some text in InDesign and run this one-liner:

app.selection[0].contents = "My new text";

That's it! Obviously, replace "My new text" with whatever text you need...

Ariel
  • 119
  • 1
  • 10