Home > Software engineering >  Photoshop script: Choose from list
Photoshop script: Choose from list

Time:01-09

I need to make an option, when running a Photoshop script, where I can choose what the script will do.

For example: When I run the script, I would like to get three options: Resize, convert to sRGB or remove background.

I can't seem to find any examples of this...

I've tried to find examples. However the internet is overflowing with examples of how to do this with javascript and HTML. But I need it for Photoshop...

CodePudding user response:

Photoshop code isn't well documented, and Photoshopp UI code less so although documented here (though not updated in ages)

However... There is a site that allows you build Photoshop UI elements with ease: scriptui.joonas.me Which is what I've done.

Then it's a matter of hooking up the dropdown selection to start your image process.

var dlg = new Window("dialog"); 
    dlg.text = "Do that thing!"; 
    dlg.orientation = "column"; 
    dlg.alignChildren = ["center","top"]; 
    dlg.spacing = 10; 
    dlg.margins = 16; 

var statictext1 = dlg.add("statictext", undefined, undefined, {name: "statictext1"}); 
    statictext1.text = "Do something"; 

var dropdown1_array = ["Resize","Convert to sRGB","Remove background"]; 
var dropdown1 = dlg.add("dropdownlist", undefined, undefined, {name: "dropdown1", items: dropdown1_array}); 
    dropdown1.selection = 0; 
    dropdown1.preferredSize.width = 150; 

// GROUP
var group1 = dlg.add("group", undefined, {name: "group1"}); 
    group1.orientation = "row"; 
    group1.alignChildren = ["left","center"]; 
    group1.spacing = 10; 
    group1.margins = 0; 

var button1 = group1.add("button", undefined, undefined, {name: "button1"}); 
    button1.text = "OK"; 
    button1.preferredSize.width = 70; 

var button2 = group1.add("button", undefined, undefined, {name: "button2"}); 
    button2.text = "Cancel"; 
    button2.preferredSize.width = 70; 

var myReturn = dlg.show(); // Show the dialog

if (myReturn == 1) // if user clicked Okay
{
  // process the image here
  var thingToDo = dropdown1.selection; // dropdown value
  alert(thingToDo);
}
  • Related