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

Script to play action via top layer name

New Here ,
Mar 07, 2021 Mar 07, 2021

Copy link to clipboard

Copied

Hi everyone

 

I've been playing around with scripting for a little while, however I don't quite understand what all is going on.

This is the script I've come up with:

 

#target photoshop

var s = app.activeDocument;

if(putName = "Flash 4" ){
app.doAction('4 Layer Flash', 'New Script Actions')
}
else {
if (putName = "Flash 3" ){
app.doAction('3 Layer Flash', 'New Script Actions')
}
else {
if (putName = "Flash 2" ){
app.doAction('2 Layer Flash', 'New Script Actions')
}
else {
if (putName = "No Flash 2" ){
app.doAction('2 Layer No Flash', 'New Script Actions')
}
}
}
}

 

What I was hoping this would do is run an action based off the top layers name which I would change to depending on how many layers I have and what I want it to do.

The issue i'm having is that even if I specify the name of the layer e.g No Flash 2 it would still run Flash 4.

 

Clearly I am doing something wrong.

 

Could anyone help me rectify where my mistakes are and what I should change?

Views

244

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

Community Expert , Mar 07, 2021 Mar 07, 2021

Your script should be set up something like this:

 

 

#target photoshop
var doc = acitveDocument;
var putName = doc.layers[0].name;

switch (putName){
    case 'Flash 4':
        app.doAction('4 Layer Flash', 'New Script Actions');
        break;
    case 'Flash 3':
        app.doAction('3 Layer Flash', 'New Script Actions');
        break;        
    case 'Flash 2':
        app.doAction('2 Layer Flash', 'New Script Actions');
        break;
    case 'Flash 1':
        app.doAction('1 Layer Fla
...

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 07, 2021 Mar 07, 2021

Copy link to clipboard

Copied

you need to either use the else if statement or switch

 

if (some condition) {some code}

else if (a different condition){code}

else if (something else){code}

 

Or a switch:

https://www.w3schools.com/js/js_switch.asp

Votes

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 07, 2021 Mar 07, 2021

Copy link to clipboard

Copied

Great thanks, I will give it a go.

If you dont mind me asking, which method would be preferrable?

Votes

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
Community Expert ,
Mar 07, 2021 Mar 07, 2021

Copy link to clipboard

Copied

I would use the switch method. I'm not at my computer, so it hard to say how to incorporate your script into a switch. 

Votes

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 07, 2021 Mar 07, 2021

Copy link to clipboard

Copied

Okay thank you, will have a look at it.

If possible and if/when you have the time. Could you play around with it and see if you can get it to work.

Thanks for your time

Votes

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 07, 2021 Mar 07, 2021

Copy link to clipboard

Copied

I'm not too familiar with all the code, I normally take bits and pieces from already existing code, how would I incorporate it into what I already have?

 

Votes

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
Community Expert ,
Mar 07, 2021 Mar 07, 2021

Copy link to clipboard

Copied

Your script should be set up something like this:

 

 

#target photoshop
var doc = acitveDocument;
var putName = doc.layers[0].name;

switch (putName){
    case 'Flash 4':
        app.doAction('4 Layer Flash', 'New Script Actions');
        break;
    case 'Flash 3':
        app.doAction('3 Layer Flash', 'New Script Actions');
        break;        
    case 'Flash 2':
        app.doAction('2 Layer Flash', 'New Script Actions');
        break;
    case 'Flash 1':
        app.doAction('1 Layer Flash', 'New Script Actions');
        break;        
    }//end switch

 

Votes

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 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

LATEST

Thanks so much, I will give it a go

Votes

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