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

Grep search in book

Participant ,
Jul 18, 2022 Jul 18, 2022

Copy link to clipboard

Copied

Hi,

I have a book with 230 files in it and I wonder if it is possible to do a grep search in those files without open it.

My skill in scripting its quite low so here is my question Â¿do i fight with the code to try it? or ¿is it better to drink a beer with my friends because it's not possible?

Thanks.

TOPICS
Scripting

Views

1.0K

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 , Jul 19, 2022 Jul 19, 2022

It's not even possible to open 230 documents: InDesign lets you open about 115 documents. One way to go about it is to create a simple script to do the replacement in one document, then use that script in a batch-processor like https://creativepro.com/files/kahrel/indesign/batch_convert.html

P.

Votes

Translate

Translate
Community Expert ,
Jul 18, 2022 Jul 18, 2022

Copy link to clipboard

Copied

Files must be open for a GREP search, but that can be handled in a script. I'm not a scripter, myself, but I suspect someone who is will want to know if the the Book file itself will be open already, or if that will also need to be done in the script, and if you have a specific search you want to do or if you want to be able to enter the search terms, and what to do if the pattern is matched.

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
Participant ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

Ok, let's answer

- The book file it can be opened. The thing is not to open 230 files.

- I have a specific search that it can be included in the script. I don't need an interface to include the grep expresion to search.

- It has to be a find and change text content.

 

Thank you for your response

 

have a great day

 

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 ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

Hi @nicosh ,

If it's only one single GREP Find/Replace action you can target all open documents in the Find/Change panel with GREP.

 

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
Participant ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

Hi Laubernder, thanks for your response.

If it's possible I don't want to open 230 files and use the find and change panel to perform the change in all the opened documents.

This the first book I have, there is another one with 180 files, so i wonder if it possible to code a script that find and change an expression in the files (without open it) of an existing book file. I assume that if it is possible find/change a single expression, i can loop an array populate with expressions to perform the find/change.

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 ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

It's not even possible to open 230 documents: InDesign lets you open about 115 documents. One way to go about it is to create a simple script to do the replacement in one document, then use that script in a batch-processor like https://creativepro.com/files/kahrel/indesign/batch_convert.html

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
Participant ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

Thank you @Laubender  and @Peter Kahrel 

For me, and my skill coding level, it is less time consuming to open, let say 50 files, and use find/change panel in all documents than to try to code a script for that task.

Have a nice day!!

 

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 ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

Peter, is it not possible to use a script to "walk through" the book files, opeing one, running the query, then closing and moving on to the next until all 230 files are done?

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 ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

That was my point: '"walk through" the book files' is exactly what the batch processor does.

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
Participant ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

I'm sorry, i didn't understand the @Peter Kahrel answer. I realized that there is a check mark to run a script. I'll give 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
Participant ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

Hi @Peter Kahrel 

Here we go again.

I run your batch processor with my script and it appears a warning -> "Undefined: undefined is not an object (108)". If I run my script without batch processing it works fine ¿any idea?

This is my code

var g = {};
g.doc = app.activeDocument;
g.cajasTexto = g.doc.stories;
g.estilosParrafo = g.doc.paragraphStyles;
g.estilosCaracter = g.doc.characterStyles;
g.fuente = "Soho Pro";
g.estiloAplicado = g.estilosParrafo.itemByName("EW_Cat_03_Info_block");
g.estiloCaracterAplicado = g.estilosCaracter.itemByName("[Ninguno]");
g.diasSemana = [['(?<=(\\s|~=|-|\\())Mon', 'lu'],
                ['(?<=(\\s|~=|-|\\())Tue', 'ma'],
                ['(?<=(\\s|~=|-|\\())Wed', 'mié'],
                ['(?<=(\\s|~=|-|\\())Thu', 'ju'],
                ['(?<=(\\s|~=|-|\\())Fri', 'vi'],
                ['(?<=(\\s|~=|-|\\())Sat', 'sá'],
                ['(?<=(\\s|~=|-|\\())Sun', 'do']];
g.meses = [['(?<=(\\s|~=|-|\\())Jan', 'ene'],
           ['(?<=(\\s|~=|-|\\())Feb', 'feb'],
           ['(?<=(\\s|~=|-|\\())Mar', 'mar'],
           ['(?<=(\\s|~=|-|\\())Apr', 'abr'],
           ['(?<=(\\s|~=|-|\\())May', 'may'],
           ['(?<=(\\s|~=|-|\\())Jun', 'jun'],
           ['(?<=(\\s|~=|-|\\())Jul', 'jul'],
           ['(?<=(\\s|~=|-|\\())Aug', 'ago'],
           ['(?<=(\\s|~=|-|\\())Sep', 'sep'],
           ['(?<=(\\s|~=|-|\\())Oct', 'oct'],
           ['(?<=(\\s|~=|-|\\())Nov', 'nov'],
           ['(?<=(\\s|~=|-|\\())Dec', 'dic']];

//Set the find options.
app.findChangeGrepOptions.includeFootnotes = false;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;


cambiarTodosItem(g.diasSemana);
cambiarTodosItem(g.meses);


function cambiarTodosItem(myArray_param) {
  for (i = 0; i < myArray_param.length; i++) {
    cambiarItem(myArray_param, g.estiloAplicado);
    //Clear the find/change preferences after the search.
    app.findGrepPreferences = NothingEnum.nothing;
    app.changeGrepPreferences = NothingEnum.nothing;
  }
}

function cambiarItem(item_arr, estiloAplicado_param) {
  app.findGrepPreferences.appliedParagraphStyle = estiloAplicado_param;
  app.findGrepPreferences.appliedFont = g.fuente;
  app.findGrepPreferences.appliedCharacterStyle = g.estilosCaracter.itemByName("[Ninguno]");
  for (i = 0; i < item_arr.length; i++) {
    app.findGrepPreferences.findWhat = item_arr[i][0];
    app.changeGrepPreferences.changeTo = item_arr[i][1];
    g.doc.changeGrep();    
  }
}

 

 

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 ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

Hi @nicosh 

will it work, if you wrap it in a self executing function like that?

 

( function()
{

/*PUT YOUR CODE HERE*/


// PLUS YOU MAY WANT TO SAVE YOUR DOCUMENT:
g.doc.save();

}() )

 

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
Participant ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

Hi again @Laubender 

I have moved all my code (from line 1 until the end) under /*Put your code here*/ line. I run the @Peter Kahrel  batch processor and a new warning appears -> "null is not an object (line 819)"

Thanks for your help

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 ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

Nicolás -- Apart from what Uwe mentioned you must set your loop counter (i) as a variable. Please insert 

 

 

var i;

 

 

At the beginning of the script, e.g. immediately before var g = {}

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
Participant ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

Nothing... The same warning ("null is not...")

This the batch processor pannel, just in case

Captura de pantalla 2022-07-19 a las 13.17.18.png

and the modified and full code, just in case

( function()
{
var i;
/*PUT YOUR CODE HERE*/
var g = {};
g.doc = app.activeDocument;
g.cajasTexto = g.doc.stories;
g.estilosParrafo = g.doc.paragraphStyles;
g.estilosCaracter = g.doc.characterStyles;
g.fuente = "Soho Pro";
g.estiloAplicado = g.estilosParrafo.itemByName("EW_Cat_03_Info_block");
g.estiloAplicadoDos = g.estilosParrafo.itemByName("EW_Cat_07_Bummer_info_block");
g.estiloAplicadoTres = g.estilosParrafo.itemByName("EW_Cat_07_Bummer_info_block_NO_RULE");
g.estiloCaracterAplicado = g.estilosCaracter.itemByName("[Ninguno]");
g.horas = [['1am', '1.00'], ['1:15am', '1.15'], ['1:30am', '1.30'], ['1:45am', '1.45'],
          ['2am', '2.00'], ['2:15am', '2.15'], ['2:30am', '2.30'], ['2:45am', '2.45'],
          ['3am', '3.00'], ['3:15am', '3.15'], ['3:30am', '3.30'], ['3:45am', '3.45'],
          ['4am', '4.00'], ['4:15am', '4.15'], ['4:30am', '4.30'], ['4:45am', '4.45'],
          ['5am', '5.00'], ['5:15am', '5.15'], ['5:30am', '5.30'], ['5:45am', '5.45'],
          ['6am', '6.00'], ['6:15am', '6.15'], ['6:30am', '6.30'], ['6:45am', '6.45'],
          ['7am', '7.00'], ['7:15am', '7.15'], ['7:30am', '7.300'], ['7:45am', '7.45'],
          ['8am', '8.00'], ['8:15am', '8.15'], ['8:30am', '8.30'], ['8:45am', '8.45'],
          ['9am', '9.00'], ['9:15am', '9.15'], ['9:30am', '9.30'], ['9:45am', '9.45'],
          ['10am', '10.00'], ['10:15am', '10.15'], ['10:30am', '10.30'], ['10:45am', '10.45'],
          ['11am', '11.00'], ['11:15am', '11.15'], ['11:30am', '11.30'], ['11:45am', '11.45'],
          ['1pm', '13.00'], ['1:15pm', '13.15'], ['1:30pm', '13.30'], ['1:45pm', '13.45'],
          ['2pm', '14.00'], ['2:15pm', '14.15'], ['2:30pm', '14.30'], ['2:45pm', '14.45'],
          ['3pm', '15.00'], ['3:15pm', '15.15'], ['3:30pm', '15.30'], ['3:45pm', '15.45'],
          ['4pm', '16.00'], ['4:15pm', '16.15'], ['4:30pm', '16.30'], ['4:45pm', '16.45'],
          ['5pm', '17.00'], ['5:15pm', '17.15'], ['5:30pm', '17.30'], ['5:45pm', '17.45'],
          ['6pm', '18.00'], ['6:15pm', '18.15'], ['6:30pm', '18.30'], ['6:45pm', '18.45'],
          ['7pm', '19.00'], ['7:15pm', '19.15'], ['7:30pm', '19.30'], ['7:45pm', '19.45'],
          ['8pm', '20.00'], ['8:15pm', '20.15'], ['8:30pm', '20.30'], ['8:45pm', '20.45'],
          ['9pm', '21.00'], ['9:15pm', '21.15'], ['9:30pm', '21.30'], ['9:45pm', '21.45'],
          ['10pm', '22.00'], ['10:15pm', '22.15'], ['10:30pm', '22.30'], ['10:45pm', '22.45'],
          ['11pm', '23.00'], ['11:15pm', '23.15'], ['11:30pm', '23.30'], ['11:45pm', '23.45'],
          ['12am', '12.00'], ['12:15am', '12.15'], ['12:30am', '12.30'], ['12:45am', '12.45'],
          ['12pm', '12.00'], ['12:15pm', '12.15'], ['12:30pm', '12.30'], ['12:45pm', '12.45'],];
g.diasSemana = [['(?<=(\\s|~=|-|\\())Mon', 'lu'],
                ['(?<=(\\s|~=|-|\\())Tue', 'ma'],
                ['(?<=(\\s|~=|-|\\())Wed', 'mié'],
                ['(?<=(\\s|~=|-|\\())Thu', 'ju'],
                ['(?<=(\\s|~=|-|\\())Fri', 'vi'],
                ['(?<=(\\s|~=|-|\\())Sat', 'sá'],
                ['(?<=(\\s|~=|-|\\())Sun', 'do']];
g.meses = [['(?<=(\\s|~=|-|\\())Jan', 'ene'],
           ['(?<=(\\s|~=|-|\\())Feb', 'feb'],
           ['(?<=(\\s|~=|-|\\())Mar', 'mar'],
           ['(?<=(\\s|~=|-|\\())Apr', 'abr'],
           ['(?<=(\\s|~=|-|\\())May', 'may'],
           ['(?<=(\\s|~=|-|\\())Jun', 'jun'],
           ['(?<=(\\s|~=|-|\\())Jul', 'jul'],
           ['(?<=(\\s|~=|-|\\())Aug', 'ago'],
           ['(?<=(\\s|~=|-|\\())Sep', 'sep'],
           ['(?<=(\\s|~=|-|\\())Oct', 'oct'],
           ['(?<=(\\s|~=|-|\\())Nov', 'nov'],
           ['(?<=(\\s|~=|-|\\())Dec', 'dic']];

g.otrosCambios = [['daily', 'todos los días'], ['noon', 'mediodía'], ['midnight', 'medianoche'], ['then taxi', 'luego taxi'], ['last adm', 'última admisión'], ['public hols', 'festivos']];

// g.Cambios = [g.horas, g.diasSemana, g.meses, g.otrosCambios]



//Set the find options.
app.findChangeGrepOptions.includeFootnotes = false;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;

cambiarTodosItem(g.horas);
cambiarTodosItem(g.diasSemana);
cambiarTodosItem(g.meses);
cambiarTodosItem(g.otrosCambios);



function cambiarTodosItem(myArray_param) {
  for (i = 0; i < myArray_param.length; i++) {
    cambiarItem(myArray_param, g.estiloAplicado); //******CAMBIAR
    //Clear the find/change preferences after the search.
    app.findGrepPreferences = NothingEnum.nothing;
    app.changeGrepPreferences = NothingEnum.nothing;
  }
}

function cambiarItem(item_arr, estiloAplicado_param) {
  app.findGrepPreferences.appliedParagraphStyle = estiloAplicado_param;
  app.findGrepPreferences.appliedFont = g.fuente;
  app.findGrepPreferences.appliedCharacterStyle = g.estilosCaracter.itemByName("[Ninguno]");
  for (i = 0; i < item_arr.length; i++) {
    app.findGrepPreferences.findWhat = item_arr[i][0];
    app.changeGrepPreferences.changeTo = item_arr[i][1];
    g.doc.changeGrep();    
  }
}


// PLUS YOU MAY WANT TO SAVE YOUR DOCUMENT:
g.doc.save();

}() )

Previously I uploaded a "light" version.

I know... it is a low level code... g.horas array (awful), so much arrays, calling four times the same function*, etc

Thanks in advance @Peter Kahrel , @Laubender 

 

* I have tried to populate another array with the four precedent (hours, days, months, other expressions) and iterate in a for loop and calling the function cambiarTodosItem one time per loop but doesn't work or may be I do not try too hard.

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 ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

Turns out that you can't use app.activeDocument because the processor opens documents but doesn't show them, so there's apparently no active document when you don't show it. Makes sense, in fact. Didn't know that, sorry.

Therefore please change 'app.activeDocument' to 'app.documents[0]' in your script. With that change in place it works fine over here.

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
Participant ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

Thanks @Peter Kahrel 

I'm really sorry but doesn't work for me.

 

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
Guru ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

Hi nicosh,

After minor changes, your script works with my batch processor.

Note: the variable called ‘g’ is the only variable that is not allowed. It’s used for exchanging data between both scripts. So, I replaced it with ‘j’. Also, I changed the font to Minion Pro and the character style to None (I am on the English version).  But ‘g.doc’ I left as it is: it’s the currently open document in the batch processor.

Here are recommended settings:

2022-07-19_20-27-32.png

The result

2022-07-19_20-28-51.png

My version of the script:

var i;

var j = {};
j.cajasTexto = g.doc.stories;
j.estilosParrafo = g.doc.paragraphStyles;
j.estilosCaracter = g.doc.characterStyles;
j.fuente = "Minion Pro";
j.estiloAplicado = j.estilosParrafo.itemByName("EW_Cat_03_Info_block");
j.estiloAplicadoDos = j.estilosParrafo.itemByName("EW_Cat_07_Bummer_info_block");
j.estiloAplicadoTres = j.estilosParrafo.itemByName("EW_Cat_07_Bummer_info_block_NO_RULE");
j.estiloCaracterAplicado = j.estilosCaracter.itemByName("[None]");
j.horas = [['1am', '1.00'], ['1:15am', '1.15'], ['1:30am', '1.30'], ['1:45am', '1.45'],
          ['2am', '2.00'], ['2:15am', '2.15'], ['2:30am', '2.30'], ['2:45am', '2.45'],
          ['3am', '3.00'], ['3:15am', '3.15'], ['3:30am', '3.30'], ['3:45am', '3.45'],
          ['4am', '4.00'], ['4:15am', '4.15'], ['4:30am', '4.30'], ['4:45am', '4.45'],
          ['5am', '5.00'], ['5:15am', '5.15'], ['5:30am', '5.30'], ['5:45am', '5.45'],
          ['6am', '6.00'], ['6:15am', '6.15'], ['6:30am', '6.30'], ['6:45am', '6.45'],
          ['7am', '7.00'], ['7:15am', '7.15'], ['7:30am', '7.300'], ['7:45am', '7.45'],
          ['8am', '8.00'], ['8:15am', '8.15'], ['8:30am', '8.30'], ['8:45am', '8.45'],
          ['9am', '9.00'], ['9:15am', '9.15'], ['9:30am', '9.30'], ['9:45am', '9.45'],
          ['10am', '10.00'], ['10:15am', '10.15'], ['10:30am', '10.30'], ['10:45am', '10.45'],
          ['11am', '11.00'], ['11:15am', '11.15'], ['11:30am', '11.30'], ['11:45am', '11.45'],
          ['1pm', '13.00'], ['1:15pm', '13.15'], ['1:30pm', '13.30'], ['1:45pm', '13.45'],
          ['2pm', '14.00'], ['2:15pm', '14.15'], ['2:30pm', '14.30'], ['2:45pm', '14.45'],
          ['3pm', '15.00'], ['3:15pm', '15.15'], ['3:30pm', '15.30'], ['3:45pm', '15.45'],
          ['4pm', '16.00'], ['4:15pm', '16.15'], ['4:30pm', '16.30'], ['4:45pm', '16.45'],
          ['5pm', '17.00'], ['5:15pm', '17.15'], ['5:30pm', '17.30'], ['5:45pm', '17.45'],
          ['6pm', '18.00'], ['6:15pm', '18.15'], ['6:30pm', '18.30'], ['6:45pm', '18.45'],
          ['7pm', '19.00'], ['7:15pm', '19.15'], ['7:30pm', '19.30'], ['7:45pm', '19.45'],
          ['8pm', '20.00'], ['8:15pm', '20.15'], ['8:30pm', '20.30'], ['8:45pm', '20.45'],
          ['9pm', '21.00'], ['9:15pm', '21.15'], ['9:30pm', '21.30'], ['9:45pm', '21.45'],
          ['10pm', '22.00'], ['10:15pm', '22.15'], ['10:30pm', '22.30'], ['10:45pm', '22.45'],
          ['11pm', '23.00'], ['11:15pm', '23.15'], ['11:30pm', '23.30'], ['11:45pm', '23.45'],
          ['12am', '12.00'], ['12:15am', '12.15'], ['12:30am', '12.30'], ['12:45am', '12.45'],
          ['12pm', '12.00'], ['12:15pm', '12.15'], ['12:30pm', '12.30'], ['12:45pm', '12.45'],];
j.diasSemana = [['(?<=(\\s|~=|-|\\())Mon', 'lu'],
                ['(?<=(\\s|~=|-|\\())Tue', 'ma'],
                ['(?<=(\\s|~=|-|\\())Wed', 'mié'],
                ['(?<=(\\s|~=|-|\\())Thu', 'ju'],
                ['(?<=(\\s|~=|-|\\())Fri', 'vi'],
                ['(?<=(\\s|~=|-|\\())Sat', 'sá'],
                ['(?<=(\\s|~=|-|\\())Sun', 'do']];
j.meses = [['(?<=(\\s|~=|-|\\())Jan', 'ene'],
           ['(?<=(\\s|~=|-|\\())Feb', 'feb'],
           ['(?<=(\\s|~=|-|\\())Mar', 'mar'],
           ['(?<=(\\s|~=|-|\\())Apr', 'abr'],
           ['(?<=(\\s|~=|-|\\())May', 'may'],
           ['(?<=(\\s|~=|-|\\())Jun', 'jun'],
           ['(?<=(\\s|~=|-|\\())Jul', 'jul'],
           ['(?<=(\\s|~=|-|\\())Aug', 'ago'],
           ['(?<=(\\s|~=|-|\\())Sep', 'sep'],
           ['(?<=(\\s|~=|-|\\())Oct', 'oct'],
           ['(?<=(\\s|~=|-|\\())Nov', 'nov'],
           ['(?<=(\\s|~=|-|\\())Dec', 'dic']];

j.otrosCambios = [['daily', 'todos los días'], ['noon', 'mediodía'], ['midnight', 'medianoche'], ['then taxi', 'luego taxi'], ['last adm', 'última admisión'], ['public hols', 'festivos']];

//Set the find options.
app.findChangeGrepOptions.includeFootnotes = false;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;

cambiarTodosItem(j.horas);
cambiarTodosItem(j.diasSemana);
cambiarTodosItem(j.meses);
cambiarTodosItem(j.otrosCambios);

function cambiarTodosItem(myArray_param) {
  for (i = 0; i < myArray_param.length; i++) {
    cambiarItem(myArray_param, j.estiloAplicado); //******CAMBIAR
    //Clear the find/change preferences after the search.
    app.findGrepPreferences = NothingEnum.nothing;
    app.changeGrepPreferences = NothingEnum.nothing;
  }
}

function cambiarItem(item_arr, estiloAplicado_param) {
  app.findGrepPreferences.appliedParagraphStyle = estiloAplicado_param;
  app.findGrepPreferences.appliedFont = j.fuente;
  app.findGrepPreferences.appliedCharacterStyle = j.estilosCaracter.itemByName("[None]");
  for (i = 0; i < item_arr.length; i++) {
    app.findGrepPreferences.findWhat = item_arr[i][0];
    app.changeGrepPreferences.changeTo = item_arr[i][1];
    g.doc.changeGrep(); 
  }
}

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
Participant ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

hi @Kasyan Servetsky

Doesn't work for me -> Finished. 0 documents were processed

 

I've replaced Minion with Soho and Character Style None to Ninguno.

I'm not testing on a book.

I've duplicated some files moved to another folder and test your solution on it (Folder and its subfolders option).

My code it's encapsulated in ¿anonymous Function?, the @Laubender solution.

 

One question: ¿why in your code there is "g."? Lines 4-6 and g.doc.changeGrep()

I've changed the remaining "g." with "j." and doesn't work.

 

 

 

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
Guru ,
Jul 22, 2022 Jul 22, 2022

Copy link to clipboard

Copied

Try it with my version of the script posted above: just replace Minion with Soho and Character Style None to Ninguno.
I haven't tested BP with scripts using anonymous functions so have no idea if it would work or not.

g — is the global variable containing so to say sub-variables and functions to interact with 'secondary' scripts.

2022-07-22_11-38-20.png

g.doc — as I mentioned in my previous post – is the reference to the currently opened doc in BP. Don't replace it with j. Alternatively, you can use app.activeDocument or app.documents[0].

BP uses its own 'namespace' to avoid clashes with vars and functions in the scripts triggered from it.

 

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
Participant ,
Jul 24, 2022 Jul 24, 2022

Copy link to clipboard

Copied

Hi @Kasyan Servetsky , the same error -> Finished. 0 documents were processed.

I don't understand why. This is my procedure:

1.- Create a new file in my code editor, Visual Studio Code.

2.- Copy&Paste your code in the file.

3.- Change "Minion" > "Soho" and "[None]" > "[Ninguno]".

4.- Save the document in the desktop, NOT in the same folder as your BP.

5.- Run your BP with this parameters.

Captura de pantalla 2022-07-24 a las 11.50.54.png

This is the structure of the folder. This folder is a subfolder of one folder in the desktop:

Captura de pantalla 2022-07-24 a las 11.50.22.png

Thank you for your answer and your patience.

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
Participant ,
Jul 24, 2022 Jul 24, 2022

Copy link to clipboard

Copied

Hi @Kasyan Servetsky don't do anything, I have to go right now and i think i have found my mistake but i can't test it.

Coming soon

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
Participant ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

@Kasyan Servetsky , @Peter Kahrel I get on my knees to apologise for wasting your time.

I am embarrassed to confess my mistake, so stupid (me and the mistake): I was running the script in Indesign 2021 when the files was Indesign 2022.

I have change my script:

1.- I have wrapped my script in anonymous function, @Laubender solution.

2..- I have change the object approach ("j = {}") to a variable aproach to avoid conflicts with @Kasyan Servetsky batch proccesor. I supposed that i have to be careful when i choose the variable names and declare it on the begging.

3.- I added a for loop to narrow down my search to three Paragraphs styles.

Here is my code, and works fine:

( function()
{
var i;
var k;
/*PUT YOUR CODE HERE*/
// var g = {};
var myDoc = app.documents[0];
var myParagraphStyles = myDoc.paragraphStyles;
var myCharacterStyles = myDoc.characterStyles;
var myFont = "Soho Pro";
var myAppliedCharacterStyle = myCharacterStyles.itemByName("[Ninguno]");
var myAppliedParagraphStyles_arr = [myParagraphStyles.itemByName("EW_Cat_03_Info_block"), myParagraphStyles.itemByName("EW_Cat_07_Bummer_info_block"), myParagraphStyles.itemByName("EW_Cat_07_Bummer_info_block_NO_RULE")];
var hours_arr = [['1am', '1.00'], ['1:15am', '1.15'], ['1:30am', '1.30'], ['1:45am', '1.45'],
          ['2am', '2.00'], ['2:15am', '2.15'], ['2:30am', '2.30'], ['2:45am', '2.45'],
          ['3am', '3.00'], ['3:15am', '3.15'], ['3:30am', '3.30'], ['3:45am', '3.45'],
          ['4am', '4.00'], ['4:15am', '4.15'], ['4:30am', '4.30'], ['4:45am', '4.45'],
          ['5am', '5.00'], ['5:15am', '5.15'], ['5:30am', '5.30'], ['5:45am', '5.45'],
          ['6am', '6.00'], ['6:15am', '6.15'], ['6:30am', '6.30'], ['6:45am', '6.45'],
          ['7am', '7.00'], ['7:15am', '7.15'], ['7:30am', '7.300'], ['7:45am', '7.45'],
          ['8am', '8.00'], ['8:15am', '8.15'], ['8:30am', '8.30'], ['8:45am', '8.45'],
          ['9am', '9.00'], ['9:15am', '9.15'], ['9:30am', '9.30'], ['9:45am', '9.45'],
          ['10am', '10.00'], ['10:15am', '10.15'], ['10:30am', '10.30'], ['10:45am', '10.45'],
          ['11am', '11.00'], ['11:15am', '11.15'], ['11:30am', '11.30'], ['11:45am', '11.45'],
          ['1pm', '13.00'], ['1:15pm', '13.15'], ['1:30pm', '13.30'], ['1:45pm', '13.45'],
          ['2pm', '14.00'], ['2:15pm', '14.15'], ['2:30pm', '14.30'], ['2:45pm', '14.45'],
          ['3pm', '15.00'], ['3:15pm', '15.15'], ['3:30pm', '15.30'], ['3:45pm', '15.45'],
          ['4pm', '16.00'], ['4:15pm', '16.15'], ['4:30pm', '16.30'], ['4:45pm', '16.45'],
          ['5pm', '17.00'], ['5:15pm', '17.15'], ['5:30pm', '17.30'], ['5:45pm', '17.45'],
          ['6pm', '18.00'], ['6:15pm', '18.15'], ['6:30pm', '18.30'], ['6:45pm', '18.45'],
          ['7pm', '19.00'], ['7:15pm', '19.15'], ['7:30pm', '19.30'], ['7:45pm', '19.45'],
          ['8pm', '20.00'], ['8:15pm', '20.15'], ['8:30pm', '20.30'], ['8:45pm', '20.45'],
          ['9pm', '21.00'], ['9:15pm', '21.15'], ['9:30pm', '21.30'], ['9:45pm', '21.45'],
          ['10pm', '22.00'], ['10:15pm', '22.15'], ['10:30pm', '22.30'], ['10:45pm', '22.45'],
          ['11pm', '23.00'], ['11:15pm', '23.15'], ['11:30pm', '23.30'], ['11:45pm', '23.45'],
          ['12am', '12.00'], ['12:15am', '12.15'], ['12:30am', '12.30'], ['12:45am', '12.45'],
          ['12pm', '12.00'], ['12:15pm', '12.15'], ['12:30pm', '12.30'], ['12:45pm', '12.45'],];
 var days_arr = [['(?<=(\\s|~=|-|\\())Mon', 'lu'],
                ['(?<=(\\s|~=|-|\\())Tue', 'ma'],
                ['(?<=(\\s|~=|-|\\())Wed', 'mié'],
                ['(?<=(\\s|~=|-|\\())Thu', 'ju'],
                ['(?<=(\\s|~=|-|\\())Fri', 'vi'],
                ['(?<=(\\s|~=|-|\\())Sat', 'sá'],
                ['(?<=(\\s|~=|-|\\())Sun', 'do']];
var months_arr = [['(?<=(\\s|~=|-|\\())Jan', 'ene'],
           ['(?<=(\\s|~=|-|\\())Feb', 'feb'],
           ['(?<=(\\s|~=|-|\\())Mar', 'mar'],
           ['(?<=(\\s|~=|-|\\())Apr', 'abr'],
           ['(?<=(\\s|~=|-|\\())May', 'may'],
           ['(?<=(\\s|~=|-|\\())Jun', 'jun'],
           ['(?<=(\\s|~=|-|\\())Jul', 'jul'],
           ['(?<=(\\s|~=|-|\\())Aug', 'ago'],
           ['(?<=(\\s|~=|-|\\())Sep', 'sep'],
           ['(?<=(\\s|~=|-|\\())Oct', 'oct'],
           ['(?<=(\\s|~=|-|\\())Nov', 'nov'],
           ['(?<=(\\s|~=|-|\\())Dec', 'dic']];

var otherExpressions_arr = [['daily', 'todos los días'], ['noon', 'mediodía'], ['Noon', 'mediodía'], ['midnight', 'medianoche'], ['then taxi', 'luego taxi'], ['last adm', 'última admisión'], ['public hols', 'festivos'], ['mid-', 'med-'], ['\\&', 'y'], ['dawn', 'amanecer'], ['dusk', 'anochecer'], ['check website', 'consultar web']];

// g.Cambios = [hours_arr, days_arr, months_arr, otherExpressions_arr]

//Set the find options.
app.findChangeGrepOptions.includeFootnotes = false;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;

cambiarTodosItem(hours_arr, myAppliedParagraphStyles_arr);
cambiarTodosItem(days_arr, myAppliedParagraphStyles_arr);
cambiarTodosItem(months_arr, myAppliedParagraphStyles_arr);
cambiarTodosItem(otherExpressions_arr, myAppliedParagraphStyles_arr);

function cambiarTodosItem(myArray_param, myParagraphStyle_param) {
  for (i = 0; i < myArray_param.length; i++) {
    cambiarItem(myArray_param, myParagraphStyle_param);
    //Clear the find/change preferences after the search.
    app.findGrepPreferences = NothingEnum.nothing;
    app.changeGrepPreferences = NothingEnum.nothing;
  }
}

function cambiarItem(item_arr, estilosAplicados_param) {
  for (k = 0; k < estilosAplicados_param.length; k++) {
    app.findGrepPreferences.appliedParagraphStyle = estilosAplicados_param[k];
    app.findGrepPreferences.appliedFont = myFont;
    app.findGrepPreferences.appliedCharacterStyle = myAppliedCharacterStyle;
    for (i = 0; i < item_arr.length; i++) {
      app.findGrepPreferences.findWhat = item_arr[i][0];
      app.changeGrepPreferences.changeTo = item_arr[i][1];
      myDoc.changeGrep();    
    } 
  }
}


// PLUS YOU MAY WANT TO SAVE YOUR DOCUMENT:
myDoc.save();

}() )

My next task is to improve my script to loop over the 4 arrays so I don't have to call the function four times, but that's another history.

Thank you all and one more time (but not enough) ¡Sorry!

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
Enthusiast ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Search only, or search and replace? I have this one to search and replace text or GREP on a folder of documents (not free but it has a trial).

http://www.marspremedia.com/software/indesign/find-change-multi-doc

 

William Campbell

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
Participant ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

Thanks @willcampbell7 

Your script it is for "global" searches and I need to narrow down to some paragraphs with a paragraph style applied.

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