Skip to main content
April 12, 2018
Answered

GREP Search “Selection” or “Story” ExtendScript ?

  • April 12, 2018
  • 2 replies
  • 4622 views

When looking for Searching via “Selection” or “Story” through GREP using a script — it expands into this convoluted rabbit hole, when you would imagine it would be much simpler .

The short and sweet script, below, works but affects the entire document. I attempted placing “selection” in various places, and tried creating variables to point to various iterations of app.pageItem.selection , app.selection , etc . To no avail.

I commented out the last line I attempted.

As always any help is very much appreciated.

Thank you.

//reset GREP preferences

app.findGrepPreferences=app.changeGrepPreferences=null;

//app.findChangeGrepOptions = app.pageItem.selection

app.findGrepPreferences.findWhat="\r";

app.changeGrepPreferences.changeTo=",\s";

app.activeDocument.changeGrep();

app.findGrepPreferences=app.changeGrepPreferences=null;

Looking for the javascript syntax that affects Find/Change > GREP > Search > Stories (and/or selection)

Correct answer lfcorullon13651490

Just try to use app.selection[0].changeGrep();

Em Qui, 12 de abr de 2018 16:48, neal derekl34934377 <

forums_noreply@adobe.com> escreveu:

Adobe Community <https://forums.adobe.com/?et=watches.email.thread>

GREP Search “Selection” or “Story” ExtendScript ?

criado por neal derekl34934377

<https://forums.adobe.com/people/neal+derekl34934377?et=watches.email.thread>

em InDesign Scripting - Visualize a discussão completa

<https://forums.adobe.com/message/10312967?et=watches.email.thread#10312967>

2 replies

Inspiring
June 4, 2025

Hello fellow scripters,

 

Adding to an old thread... You can also target the grep find change to a single story, e.g.

var doc = app.documents[0];

doc.stories[0].changeGrep();

// or

doc.textFrames[0].parentStory.changeGrep();

// or

doc.textFrames.itemByName("frame_name").parentStory.changeGrep();

 

Cheers!

Funtom

lfcorullon13651490
lfcorullon13651490Correct answer
Legend
April 12, 2018

Just try to use app.selection[0].changeGrep();

Em Qui, 12 de abr de 2018 16:48, neal derekl34934377 <

forums_noreply@adobe.com> escreveu:

Adobe Community <https://forums.adobe.com/?et=watches.email.thread>

GREP Search “Selection” or “Story” ExtendScript ?

criado por neal derekl34934377

<https://forums.adobe.com/people/neal+derekl34934377?et=watches.email.thread>

em InDesign Scripting - Visualize a discussão completa

<https://forums.adobe.com/message/10312967?et=watches.email.thread#10312967>

uniqued_tol
Inspiring
April 12, 2018

"\r" instead  "\\r" "\s" instead "\\s"

FRIdNGE
April 12, 2018

… About catching an "active story", e.g. placing the cursor inside it, "app.selection[0].parentStory"

Best,

Miche!, from FRIdNGE