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?

TOPICS
How to, Problem or error

Views

71

Likes

translate

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

Adobe Community Professional , 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...

Likes

translate

Translate

Translate
Adobe Community Professional ,
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

Likes

translate

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?

Likes

translate

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 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. 

Likes

translate

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

Likes

translate

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?

 

Likes

translate

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

 

Likes

translate

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

Thanks so much, I will give it a go

Likes

translate

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