Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


how to run the javascript in all active indesign documents?

Explorer ,
Feb 02, 2018 Feb 02, 2018

Copy link to clipboard

Copied

Hello all,

Newie here. I browsed through the different forums and assembled a simple script to set up the column and gutter on an indesign page, It's not this simple, it will be expanded later.

var doc = app.activeDocument;

var page = doc.pages.item(0);

    page.marginPreferences.properties = {

       columnCount: 12,

        columnGutter: 0

        };

it works when run via Indesign script menu on the active document. I would like it so that it runs on all open documents. I googled far and wide, and found some sample, but i could not make it work, either syntax errors, var undefined, etc.

I tried the suggestion from how to apply my script to all opened files?, it didn't work.

It didn't work for me.

while (documents.length > 0) {

var doc = app.activeDocument;

var page = doc.pages.item(0);

    page.marginPreferences.properties = {

       columnCount: 12,

        columnGutter: 0

        }

app.activeDocument.close()

}

I tried copying from another script that Mr. Kuhrel helped me with prior, it still runs but only on the active window.

The variables are not correct, that much i can tell but i don't know how to fix it.

for (var i = app.documents.length-1; i >= 0; i--) {

var doc = app.activeDocument;

var page = doc.pages.item(0);

    page.marginPreferences.properties = {

       columnCount: 3,

        columnGutter: 0

}

Is there a universal wrapper that can be used to //insert codes here — to run on all open documents in indesign?

Regards and have a great weekend.

TOPICS
Scripting

Views

2.0K

Likes

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

Mentor , Feb 03, 2018 Feb 03, 2018
Hi,Closing doc while script run and keep relation for its execution on current DOM status can lead you into false result.I suggest to use Peter Kahrel way with one modification:for (var i = app.documents.length-1; i >= 0; i--) {  var doc = app.documents;  var page = doc.pages.item(0);      page.marginPreferences.properties = {        columnCount: 3,          columnGutter: 0  }    }Jarek

Likes

Translate

Translate
Adobe Community Professional ,
Feb 02, 2018 Feb 02, 2018

Copy link to clipboard

Copied

In your second javascript example, change the top line:

while (documents.length > 0) {

to the following:

while (app.documents.length > 0) {

Otherwise, there are other ways to run a script (or lots of scripts) to many documents. Check out this thread here:

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

Likes

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
New Here ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

Hello,

 

i have nearly the same issue, i want to save all opened pdf documents.. It is only saving one document to the path, can you help me please? 

 

while (app.documents.length > 0) {

this.saveAs("D:/Users/TestUser/Desktop/" + this.documentFileName);

app.activeDocument.close()

}

 

Likes

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
Mentor ,
Feb 03, 2018 Feb 03, 2018

Copy link to clipboard

Copied

Hi,

Closing doc while script run and keep relation for its execution on current DOM status can lead you into false result.

I suggest to use Peter Kahrel way with one modification:

  1. for (var i = app.documents.length-1; i >= 0; i--) { 
  2. var doc = app.documents
  3. var page = doc.pages.item(0); 
  4.     page.marginPreferences.properties = { 
  5.       columnCount: 3
  6.         columnGutter: 0 
  7. }   
  8. }

Jarek

Likes

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
New Here ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

Hello,

 

i have nearly the same issue, i want to save all opened pdf documents.. It is only saving one document to the path, can you help me please? 

 

while (app.documents.length > 0) {

this.saveAs("D:/Users/TestUser/Desktop/" + this.documentFileName);

app.activeDocument.close()

}

 

 

I think i know my fault.. "this" only saves one doc in my case, maybe the solution is an array? I really dont know how to code this, im new in adobe scripting

Likes

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
Adobe Community Professional ,
Mar 22, 2021 Mar 22, 2021

Copy link to clipboard

Copied

i want to save all opened pdf documents.

 

You can’t open a PDF into InDesign (you can only Place PDFs), so maybe you are looking for an Acrobat script?

 

For InDesign files you don’t need a file path unless they are new documents, so this would work for existing doc:

 

while (app.documents.length > 0) {
    app.activeDocument.save()
    app.activeDocument.close()
}

 

If you wanted a save as to a specified folder then:

 

var fld = Folder.desktop

while (app.documents.length > 0) {
    app.activeDocument.save(File(fld + "/" +app.activeDocument.name))
    app.activeDocument.close()
}

 

Likes

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
New Here ,
Mar 23, 2021 Mar 23, 2021

Copy link to clipboard

Copied

Hello, thanks for your help but this didnt worked for me.

Yes i am looking for a script in adobe acrobat pro dc. 

For example: i am opening 10 pdf files from SAP (only opened, it isnt saved local!) and after that i want to save all of them with one action (a script) on a specific folder. i dont want to save them one by one, it takes too much time.

 

is this possible?

 

I am using the Java Script debugger in acrobat. 

 

Your Code gave me syntax error, see below (attachement)

 

 

Likes

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
Adobe Community Professional ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

LATEST

Likes

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

Copy link to clipboard

Copied

Sorry for the later reply, this is exactly what I needed. Thank you both!!

Likes

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