Skip to main content
Inspiring
June 7, 2022
Answered

Open all indd files from a folder and create a text box in each file.

  • June 7, 2022
  • 3 replies
  • 524 views

var sourceFolder = Folder.selectDialog("select a folder");

var myFiles = sourceFolder.getFiles("*indd");

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

   {

    app.open(myFiles[i]);   

    app.activeDocument.pages[0].textFrames.add();     // can we another variable instead of activeDocument something like app.myFiles[i].pages[0].textFrames.add(); 

   }

This topic has been closed for replies.
Correct answer m1b

Hi @virender_CTS, you probably have enough answers to go on, but you didn't mention what your scripting experience was, so maybe you need some more targetted help. See comments in code below.

- Mark

 

var sourceFolder = Folder.selectDialog("select a folder");
// check if sourceFolder isn't null/undefined/zero
// it will be null if user cancelled select dialog
if (sourceFolder) {
    var myFiles = sourceFolder.getFiles("*indd");
    for (i = 0; i < myFiles.length; i++) {
        // store the opened document in variable
        var doc = app.open(myFiles[i]);
        // example of another variable that uses doc
        var width = doc.pages[0].bounds[3];
        // like Uwe's post
        doc.pages[0].textFrames.add(
            {
                geometricBounds: ["-10mm", "0mm", "-3mm", width],
                contents: "This text is off the page."
            }
        );
    }
}

 

3 replies

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
June 7, 2022

Hi @virender_CTS, you probably have enough answers to go on, but you didn't mention what your scripting experience was, so maybe you need some more targetted help. See comments in code below.

- Mark

 

var sourceFolder = Folder.selectDialog("select a folder");
// check if sourceFolder isn't null/undefined/zero
// it will be null if user cancelled select dialog
if (sourceFolder) {
    var myFiles = sourceFolder.getFiles("*indd");
    for (i = 0; i < myFiles.length; i++) {
        // store the opened document in variable
        var doc = app.open(myFiles[i]);
        // example of another variable that uses doc
        var width = doc.pages[0].bounds[3];
        // like Uwe's post
        doc.pages[0].textFrames.add(
            {
                geometricBounds: ["-10mm", "0mm", "-3mm", width],
                contents: "This text is off the page."
            }
        );
    }
}

 

Inspiring
June 8, 2022

HI Mark,

I am just a few steps ahead than a beginnger but lost touch in scritps since the Pandemic. Trying to be active now.

I understood the following code which I was looking foir. Thank you! 

        var doc = app.open(myFiles[i]);

 

Community Expert
June 7, 2022

Hi virender_CTS,

don't know exactly what you are asking here.

FWIW: If you open a single InDesign file with app.open() the method will return a single document you can work with.

var doc = app.open( InDesignFile );

doc.pages[0].textFrames.add
(
	{
		geometricBounds : [ "50mm" , "50mm" , "100mm" , "100 mm" ] ,
		contents : "Hello, World" ,
		fillColor : "None" ,
		strokeColor : "None"
	}
);

 

Regards,
Uwe Laubender
( Adobe Community Professional )

 

Inspiring
June 8, 2022

Hi Uwe,

Thanks for the reply. I have just started re-creating those scripts which I created before Mar 2020 (before lockdown) in office machine.

Got a basic doubt so asked.

Kasyan Servetsky
Legend
June 7, 2022

You can write a one-line script and run it from the Batch processor.

Instead of the active document, you can use g.doc which is the global variable (available in both scripts) for the current document opened by BP.