Skip to main content
Apr 12, 2018 7:43 PM UTC
Answered

GREP Search “Selection” or “Story” ExtendScript ?

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)

lfcorullon13651490
lfcorullon13651490Correct answer
Legend
Apr 12, 2018 8:01 PM UTC

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>

12 replies

Inspiring
Jun 4, 2025 5:08 AM UTC

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

Translate
lfcorullon13651490
lfcorullon13651490Correct answer
Legend
Apr 12, 2018 8:01 PM UTC

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>

Translate
uniqued_tol
Inspiring
Apr 12, 2018 8:29 PM UTC

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

Translate
FRIdNGE
Apr 12, 2018 8:36 PM UTC

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

Best,

Miche!, from FRIdNGE

Translate