Skip to main content
Known Participant
June 28, 2022
Answered

FindChangeByList doesn't work

  • June 28, 2022
  • 6 replies
  • 892 views

I've written a command in my FindChangeByList file, but I don't know why it's not working. Here's the code:

grep	{findWhat:"(\bX\b)[~m~>~f~| ~S~s~j~<~/~.~3~4~%]{1,}(\bY\b)"}	{changeTo:"$1$2"}	{includeFootnotes:true, includeMasterPages:false, includeHiddenLayers:true, wholeWord:false}

It's supposed to find the words X and Y with whatever ant any number of spaces between them, and put them together. I think the problem may be related to the \b command inside the parentheses because when I delete them, it's working.
Besides, is it possible to have a dialog box in the jsx file to see the number of changes that the FindChangeByList has made at the end of running?

This topic has been closed for replies.
Correct answer Barb Binder

@Pickory: I think you are right. When I dragged the files from the script folder to the dropbox folder they duplicated without me holding down the Option key. I was surprised but then didn't think anything more about it. 🙄

 

@SunFlower16 Try this link. I'm around for a few hours in case it doesn't work. Just let me know. 

https://www.dropbox.com/scl/fo/eg6rsi5qd5d9wxbevtqec/h?dl=0&rlkey=hb2szz71d7s6jzffdsvrmp612

 

~Barb

6 replies

Community Expert
June 29, 2022

Ok, @SunFlower16 ,

findWhat is expecting a string.

With /myRegExp/.source it gets a string, because the regular expression, the RegExp, is "converted" (coerced) to a string.

 

Hm…

/\n/.source === "\\n";

Returns true. The expression on the left of the tripple = is identical to the expression on the right.

So double-escaping should not be necessary.

 

One could test this with full ExtendScript code for InDesign to populate the GREP Find field in the GUI. Run this code:

app.findGrepPreferences.findWhat = /\n/.source;

Look up the result in the GUI under the GREP Find field:

 

So:

app.findGrepPreferences.findWhat = /(\bX\b)\h+(\bY\b)/.source;

will show up like this:

 

The same should happen with the list in FindChangeByList.

Either do that:

grep   {findWhat: "(\\bX\\b)\\h+(\\bY\\b)"}

or write it this way:

grep   { findWhat : /(\bX\b)\h+(\bY\b)/.source }

 

With ExtendScript this expression will return true:

"(\\bX\\b)\\h+(\\bY\\b)" === /(\bX\b)\h+(\bY\b)/.source // will return true

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Barb Binder
Community Expert
Community Expert
June 29, 2022

You can give all the credit to @Manan Joshi. He taught me everything I know about Find/ChangeByList! 😊

 

~Barb

~Barb at Rocky Mountain Training
Barb Binder
Community Expert
Barb BinderCommunity ExpertCorrect answer
Community Expert
June 29, 2022

@Pickory: I think you are right. When I dragged the files from the script folder to the dropbox folder they duplicated without me holding down the Option key. I was surprised but then didn't think anything more about it. 🙄

 

@SunFlower16 Try this link. I'm around for a few hours in case it doesn't work. Just let me know. 

https://www.dropbox.com/scl/fo/eg6rsi5qd5d9wxbevtqec/h?dl=0&rlkey=hb2szz71d7s6jzffdsvrmp612

 

~Barb

~Barb at Rocky Mountain Training
Known Participant
June 29, 2022

Thanks a million dear Barb. It's working properly.
@Barb Binder @Pickory I also modified my own code. To my surprise when I implemented both //.source and the escaped backslash, it started working. I mean I wrote this:

{findWhat:/(\\bX\\b)\\h+(\\bY\\b)/.source}

 I really don't know why, but it's up and running too.

Barb Binder
Community Expert
Community Expert
June 28, 2022

Hi Brad:

 

Here is a link to the two files I created to answer your question. 

https://www.dropbox.com/sh/5gbghni11clyfsy/AABCg7p5pBDpjfvzpxbQgh3Ka?dl=0

 

Put the .jsx file in the JavaScript folder. Put the .txt file in the JavaScript\FindChangeSupport folder. Note: if you change the file names, you will need to change the reference to the .txt file in the .jsx file.

 

~Barb

 

~Barb at Rocky Mountain Training
Known Participant
June 29, 2022

Your txt file seems corrupted. Could you kindly please double-check?

Barb Binder
Community Expert
Community Expert
June 28, 2022

Hi @SunFlower16:

 

All of the backlashes need to be escaped as per this line in the file:

//If you enter backslashes in the findWhat property of the findGrepPreferences object, they must be "escaped"
//as shown in the example below:
//
//{findWhat:"\\s+"}
 
That said, this works for me. \h+ matches all horizontal spaces, which reduces the complexity of expression. It's working in my test, but of course we haven't seen your file.
 
grep   {findWhat: "(\\bX\\b)\\h+(\\bY\\b)"}   {changeTo:"$1$2"}   {includeFootnotes:true, includeMasterPages:false, includeHiddenLayers:true, wholeWord:false}
 
~Barb
 
~Barb at Rocky Mountain Training
Known Participant
June 28, 2022

Could you kindly please provide me with your file or your code? I couldn't manage to do it maybe because I'm a newbie.
Here's my file:
https://drive.google.com/file/d/1ziJgxaqWSYzOiDec_UqFCtEWn_lsLYq3/view?usp=sharing

Note that my file is a combination of the JSX and the TXT file, so it's standalone. 

Community Expert
June 28, 2022

I suppose you will have to escape the \ so \b would be \\b. Try it hopefully it will work

-Manan

-Manan
Known Participant
June 28, 2022

I tried but it didn't work, I'm afraid. Could you please give it a try?