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

Iterate over all document layers applescript

Community Beginner ,
Jun 07, 2013 Jun 07, 2013

Hi,I have experience as programmer but not in applescript or photoshop scritpting,

Basically I want to apply some actions to layers, but only to those layers that are named ending in '-changeMe' e.g ( 'Layer 1-changeMe', 'Background-changeMe')

I'm trying to convert the pseudocode below to applescript

foreach layer in CurrentDocument.layers

   if layer.name contains '-changeMe'

       do something

   end if

end foreach

In the pseudocode above I'm inveting the notation, but I hoppe you get the idea.

it's posible?

Thanks!

TOPICS
Actions and scripting
1.7K
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

correct answers 1 Correct answer

Community Beginner , Jun 09, 2013 Jun 09, 2013

Thanks guys for the help, I finally manage to mix applescript and javascript, simply awesome.

--target Photoshop CS6

tell application "Adobe Photoshop CS6"

do javascript "

           var theLayers = app.activeDocument.layers;

var LayersName, result;

var searchString = /[-]changeMe/;

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

    LayersName = theLayers.name;

    result = LayersName.search(searchString);

    if (result != -1) {

        alert('Found in layer: '+LayersName);

        // or do something else

    }

}

    

...
Translate
Adobe
Community Expert ,
Jun 07, 2013 Jun 07, 2013

Would you be willing to use JavaScript instead?

I think at least one of the regulars in this Forum is AppleScript savvy, but most people seem to avoid it for Photoshop Scripting purposes.

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 Beginner ,
Jun 07, 2013 Jun 07, 2013

Yes, I love javascript, but I'm wondering if it's posible to launch javascript  actions from actionscript.  Because I want to have some actions integrated at the OS level, to have the posibility for example to right click on a folder or file and launch the script from there, passing the folder path or file as an argument.

Not sure if I can call javascript from applescript.

Apart of that I'm intresting to see javascript solutions to the same problem, I may still change my mind while practicing.

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
Guru ,
Jun 08, 2013 Jun 08, 2013

Yes you can call any JavaScript syntax including Action Manager syntax from AppleScript… You pass the command a string or file to the JS and it also takes arguments…

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 ,
Jun 09, 2013 Jun 09, 2013

I can't help you with AppleScript.

But this JavaScript works.

// FindStringInLayersName.jsx

// http://forums.adobe.com/thread/1227665?tstart=0

// find layers which have "-changeMe" in the name

var theLayers = app.activeDocument.layers;

var LayersName, result;

var searchString = /[-]changeMe/;

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

    LayersName = theLayers.name;

    result = LayersName.search(searchString);

    if (result != -1) {

        alert("Found in layer: "+LayersName);

        // or do something else

    }

}

Perhaps someone else can translate this.

Good luck

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 Beginner ,
Jun 09, 2013 Jun 09, 2013
LATEST

Thanks guys for the help, I finally manage to mix applescript and javascript, simply awesome.

--target Photoshop CS6

tell application "Adobe Photoshop CS6"

do javascript "

           var theLayers = app.activeDocument.layers;

var LayersName, result;

var searchString = /[-]changeMe/;

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

    LayersName = theLayers.name;

    result = LayersName.search(searchString);

    if (result != -1) {

        alert('Found in layer: '+LayersName);

        // or do something else

    }

}

          "

end tell

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