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

how to apply my script to all opened files?

New Here ,
May 19, 2017 May 19, 2017

Hi,

I'm trying to replace the content of text variables in my PSD thanks to a javascript script.

The script works but I'd like to push it a little bit further

I'd like to apply this script to all opened files. Ideally I'd like to get in a variable the list of all opened documents and then use a for loop to go through all items and apply my loop.

See my script below:

if(app.documents.length != 0){

    var doc = app.activeDocument;

    var headline = "new headline"

    var body = "new body copy"

    var cta = "you're going to be rich sucker"

    var url = "http://www.nicesite.com"

 

    for(i = 0; i < doc.artLayers.length; ++i){

        var layer = doc.artLayers;

        if(layer.name == "headline"){

         

            layer.textItem.contents = headline;

  }

        if(layer.name == "body"){

         

            layer.textItem.contents = body;

        }

        if(layer.name == "cta"){

         

            layer.textItem.contents = cta;

        }

        if(layer.name == "url"){

         

            layer.textItem.contents = url;

        }

    }

}

Would you mind sharing some code which could allow me to apply this treatment to all the open files I have in my photoshop environment?


Thanks

TOPICS
Actions and scripting
3.5K
Translate
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 Expert ,
May 19, 2017 May 19, 2017

Easiest would be a while-function, I guess,

while (documents.length > 0) {

/*insert the operation here*/

app.activeDocument.close()

}

that concludes with closing the active document.

But a for-function should also work.

for (var m = 0; m < documents.length; m++) {

var theDoc = app.documents;

app.activeDocument = theDoc;

/*insert the operation here*/

}

Translate
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
May 19, 2017 May 19, 2017

I would go with the while loop. Your for loop is going to skip documents if you close them in the loop.

Translate
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 ,
May 21, 2017 May 21, 2017
LATEST

You are right, when closing in the for-function one should subtract and a while-function would be simpler.

Translate
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