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

FindChangeByList doesn't work

Explorer ,
Jun 28, 2022 Jun 28, 2022

Copy link to clipboard

Copied

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?

TOPICS
Scripting

Views

324

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

correct answers 1 Correct answer

Community Expert , Jun 29, 2022 Jun 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

Votes

Translate

Translate
Community Expert ,
Jun 28, 2022 Jun 28, 2022

Copy link to clipboard

Copied

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

-Manan

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
Explorer ,
Jun 28, 2022 Jun 28, 2022

Copy link to clipboard

Copied

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

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 ,
Jun 28, 2022 Jun 28, 2022

Copy link to clipboard

Copied

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

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
Explorer ,
Jun 28, 2022 Jun 28, 2022

Copy link to clipboard

Copied

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. 

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 ,
Jun 28, 2022 Jun 28, 2022

Copy link to clipboard

Copied

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

 

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
Explorer ,
Jun 28, 2022 Jun 28, 2022

Copy link to clipboard

Copied

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

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
Guide ,
Jun 28, 2022 Jun 28, 2022

Copy link to clipboard

Copied

Hi Barb,

It looks like you might have copied file alias to dropbox.

 

P.

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 ,
Jun 29, 2022 Jun 29, 2022

Copy link to clipboard

Copied

@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

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
Explorer ,
Jun 29, 2022 Jun 29, 2022

Copy link to clipboard

Copied

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.

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 ,
Jun 29, 2022 Jun 29, 2022

Copy link to clipboard

Copied

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

 

~Barb

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 ,
Jun 29, 2022 Jun 29, 2022

Copy link to clipboard

Copied

LATEST

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:

FindWhat with .source RESULT in GREP Find field.PNG

 

So:

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

will show up like this:

FindWhat with .source RESULT-SAMPLE-2 in GREP Find field.PNG

 

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 )

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