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

How to take an existing script and apply it to multiple documents

Community Beginner ,
Jan 31, 2018 Jan 31, 2018

Copy link to clipboard

Copied

I would like to take an existing script, but have it run on multiple documents that I have open (or select from a set of unopened files)

For example, run the ExportAllStories.jsx on multiple documents

Is there a chunk of text I can just copy and paste into it to make this happen?

TOPICS
Scripting

Views

863

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 ,
Jan 31, 2018 Jan 31, 2018

Copy link to clipboard

Copied

When I need something like this, I use this code I wrote sometime ago...

TO RUN IN FILES SAVED IN A FOLDER:

//=============================================================

//  Script by Luis Felipe Corullón

//  Contato: lf@corullon.com.br

//  Site: http://lf.corullon.com.br

//=============================================================

var myFileFolder = Folder(/*HERE GOES THE DEFAULT FOLDER*/).selectDlg("Select the folder.");

var myDialog = myFileFolder;

if (myDialog != null) {

    var myIDFiles = myFileFolder.getFiles("*.indd");

    alert (myIDFiles.length + " files were found in the selected.","Script by LFCorullón");

    for (var z = 0; z < myIDFiles.length; z++) {

        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

        app.open(File(myIDFiles));

//~ =========================================================================================================

//~ =========================================================================================================

// HERE GOES THE CODE TO BE EXECUTED IN EACH FILE

       

// HERE GOES THE CODE TO BE EXECUTED IN EACH FILE

//~ =========================================================================================================

//~ =========================================================================================================

        app.activeDocument.close(SaveOptions.YES);

        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

        }

    }

TO RUN IN FILES SAVED IN A FOLDER AND ALL SUBFOLDERS:

//=============================================================

//  Script by Luis Felipe Corullón

//  Contato: lf@corullon.com.br

//  Site: http://lf.corullon.com.br

//=============================================================

var myFolder = Folder(/*the specified folder here*/).selectDlg("Select the main folder.");

// se o usuário pressionar OK na JANELA DE DIALOGO

var myDialog = myFolder;

if(myDialog == null){

        alert ("Canceled.","Script by LFCorullón");}

else {

    var myFiles = [];

    GetSubFolders(myFolder);

    alert (myFiles.length + " files found in the main folder and subfolders.","Script by LFCorullón");

//open files in the selected folder and subfolders

for(var i = 0; i < myFiles.length; i++)

    {

//não exibe nenhuma janela de interação.

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

//turn check links off

app.linkingPreferences.checkLinksAtOpen = false;

    app.open(File(myFiles));

//~ =========================================================================================================

//~ =========================================================================================================

// EXECUTA A AÇÃO EM CADA UM DOS ARQUIVOS DA PASTA SELECIONADA

       

       

// EXECUTA A AÇÃO EM CADA UM DOS ARQUIVOS DA PASTA SELECIONADA

//~ =========================================================================================================

//~ =========================================================================================================

//turn check links on again

app.linkingPreferences.checkLinksAtOpen = true;

//exibe todas as janelas de interação.

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

    }

alert (myFiles.length + " files in the main folder and subfolders were processed.","Script by LFCorullón");}

function GetSubFolders(theFolder) { 

     var myFileList = theFolder.getFiles(); 

     for (var i = 0; i < myFileList.length; i++) { 

          var myFile = myFileList

          if (myFile instanceof Folder){ 

               GetSubFolders(myFile); 

          } 

          else if (myFile instanceof File && myFile.name.match(/\.indd$/i)) { 

               myFiles.push(myFile); 

          } 

     } 

}

Hope it 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
People's Champ ,
Feb 01, 2018 Feb 01, 2018

Copy link to clipboard

Copied

You may be interested by Kasyan Servetsky​ Batch process Script:

Batch processor

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 ,
Feb 01, 2018 Feb 01, 2018

Copy link to clipboard

Copied

LATEST

Or Peter Kahrel's

Free script Batch convert/export InDesign documents | Peter Kahrel

where you can use its "Run a script" function.

Regards,
Uwe

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