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 apply my script to all opened files?

New Here ,
May 19, 2017 May 19, 2017

Copy link to clipboard

Copied

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

Views

2.2K

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

Copy link to clipboard

Copied

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*/

}

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

LATEST

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

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