CS UI

Are there some examples of script dialogue boxes (or UI )?? I've had a look at CSUIB 2.0 but it's not javascript friendly - which doesn't help when you don't know what's wrong. Ultimately I want to create a dialogue box that is populated by the layers in a photoshop file. Each of the layers listed is to be given a radio button so the user can switch them on or off. After which I can then pass a function to each selected layers.
Here's what I've got so far:
var dlg =
"dialog {text:'Script Interface',bounds:[100,100,420,510]," +
"radiobutton0:RadioButton {bounds:[110,330,211,350] , text:'layerName0' }," +
"radiobutton1:RadioButton {bounds:[110,300,211,320] , text:'layerName1' }," +
"button0:Button {bounds:[30,370,130,390] , text:'cancel' }," +
"button1:Button {bounds:[170,370,270,390] , text:'OK' }};";
var win = new Window(dlg,"my dialogue");
win.center();
win.show();
I don't know why the rado buttons aren't working as they should. Any ideas?

Hi Ghoulfool,
I'm on CS3 but I don't think that's the problem.
It's getting a bit specific to my needs, which is bad because I can't build the script without forum help.
It assumes you have a file that's built to reflect the layers and actions available in the arrays I set up at the start of the script.
It also assumes of course that you also have the named actions available in the named action set!
No-one's going to have a document/actions just like that and I'm contractually forbidden from attaching one.
I'm hoping someone might know enough scripting to see the problems and offer advice regardless.
Currently I'm at an impasse and considering a total rewrite.
Perhaps if I just start with a script that builds an array of all layers (including those within layersets) first, then I might be beter placed to create a recursive function or for loop that can run actions on those layers?
Any advice after perusing the following would be welcome...
// Run Action on All Matched Layers- Adobe Photoshop Script
// Description: searches all layers, including grouped layers, by name and selects the first match, running a chosen action on the layer.
// Requirements: Adobe Photoshop CS2, or higher
// Version: 0.1.1, 8/June/2010
// Author: Tom Barnfield ([email protected])
// Website: http://www.runninghead.com
// ============================================================================
// Installation:
// 1. Place script in 'C:\Program Files\Adobe\Adobe Photoshop CS3#\Presets\Scripts\'
// 2. Restart Photoshop
// 3. Choose File > Scripts > run action on all matched layers.jsx
// ============================================================================
// TO DO: Pair actions with layers and sort call action routine.
// For reference:
//~ win.dropdownlist.onChange = function() {
//~    //Save the selected value in a variable to be used later
//~    myActions = actions_array[parseInt(this.selection)];
//~    };
// enable double-clicking from Mac Finder or Windows Explorer
// this command only works in Photoshop CS2 and higher
#target photoshop
// bring application forward for double-click events
app.bringToFront();
// FYI: You can call Actions with this script like so-
// doAction('setup PS CS3 on load','toms ps actions 3 7 8');
// Declare variables:
var chosen_action = null;//'default var declaration in line 31';
//var item;//del?
var myTitle = 'Customize your Processing :)';
var done_layers_array = new Array();
// Previouisly in modal dlg box was 'folderSamples'.
var standard_layers_array = new Array(
'stitching',
'sawtooth',
'ticking',
'shading',
'outer hairs',
'eyes',
'nose la',
'muzzle line'
var actions_array = new Array(
'none', // Default initial state, avoid by use of a  +1 in the loops if necessary.
'lt to st stitching action', // stitching
'lt to st stitching action', //sawtooth
'prepare ticking layers lt to st', // ticking
'none', // shading
'lt to st outer hairs action', // outer hairs
'lt to st eyes action', // eyes
'lt to st stitching action', // nose line
'lt to st stitching action', // eyes
var dropdownlist_array = new Array();// The array of drop down lists.
var chosen_actions_array = new Array();// The array of chosen actions, must corespond to the numnber of chosen layers.
var ui = // dialog resource object
     'dialog { \
          orientation: "row", alignChildren: "row", \
          main_panel: Panel { \
               orientation: "row", alignChildren: "left", \
               group1: Group { \
                    orientation: "column", alignChildren: "left"\
               group2: Group { \
                    orientation: "column", \
          buttons_group: Group { \
               orientation: "column", alignment: "left", \
               goBtn: Button {text:"Go!", properties:{name:"Go"} }, \
               cancelBtn: Button { text:"Cancel", properties:{name:"cancel"} }, \
     var win = new Window (ui); // new window object with UI resource
     // Reset all text in the main_panel titles and buttons:
     win.main_panel.text = myTitle;
     win.buttons_group.goBtn.name = 'Go';
     win.buttons_group.cancelBtn.text = 'Cancel';
// Create a column of check boxed layer names:
for(var i = 0; i < standard_layers_array.length; i++) {
     win.main_panel.group1.add('checkbox', undefined, standard_layers_array[i]);
// Create a column of dropdown menus:
for(var i = 0; i < standard_layers_array.length; i++) {
     dropdownlist_array[i] = win.main_panel.group2.add('dropdownlist', undefined, actions_array);
     dropdownlist_array[i].selection = [i+1] ;//Make the first item in list appear instead of a blank (= 0).
     // When the dropdown selection is changed by the user, update the chosen _actions _array:
     dropdownlist_array[i].onChange = function (){
          chosen_actions_array[i] = this.selected.text;
          alert(chosen_actions_array);
//Go button:
win.buttons_group.goBtn.onClick = function() {
     for (var i = 0; i < standard_layers_array.length; i++) {
          chosen_actions_array.push(dropdownlist_array[i].selection.text);
     // Display an alert to show the chosen_actions_array is working:
//~      var msg = '';
//~      for (var i = 0; i < chosen_actions_array.length; i++) {
//~           msg += chosen_actions_array[i] + '\n';
//~           }
//~      alert ('Chosen_actions_array returns:\n\n' + msg);
     win.close(1); // 1 in the brackets means Closed like "OK", 2 means closed like "Cancel".
// Cancel button (not strictly needed as the default action for the goBtn is 'close')
win.buttons_group.cancelBtn.onClick = function() {
    win.close(2); // 1 in the brackets means Closed like "OK", 2 means closed like "Cancel".
win.show();
win.center();// move to center before
// ============================================================================
// main - main function
function main(name) {
     // prompt for layer name (first run)
//~      if (!name) {
//~           var name = prompt('Enter the kind of layers you wish to run the action on (eg- "shading", "outer hairs" or "ticking":', 'stitching', 'Type of Layers to Work On');
//~      } else {// prompt for layer name (after unsuccessful find)
//~           name = prompt('"' + name + '" not found.\n\n' +
//~           'Perhaps because we\'re finished processing the document now?\n\n' +
//~           'Would you like try another search?', name, 'Find Layer');
//~      }
//var chosen_action = prompt ('Now choose an action to run\nThis must be available in \"toms ps cbg actions 7 4 10.\"', 'lt to st stitching action', 'Action to run');
     // find layer; quit on cancel button or escape key
     //if (name) {
          var match = findLayer(activeDocument);
          // repeat find if layer not found
          if (!match) {
               main(name);
// findLayer - iterate through layers to find a match
function findLayer(ref) {
     // declare local variables
     var layers = ref.layers;
     var match = false;
          // iterate through layerstack to find a match
          for (var i = 0; i < layers.length; i++) {
               var layer = layers[i];
               if (layer.typename == 'LayerSet') {// If it's a layerset, go in one level and carry on.
               match = findLayer(layer);
               } else {// This must be a real layer...
               // Looping layer processor
               for (var i = 0; i < standard_layers_array.length; i++) {
                    var name = standard_layers_array[i];
                    // test for matching layer
                    var current_layer_full_address =  (layer.parent.name.toLowerCase() + '.' + layer.name.toLowerCase());
                    alert(layer.parent.name.toLowerCase() + '.' + layer.name.toLowerCase());
                    if ((layer.name.toLowerCase().indexOf (name, 0)!=-1) && (done_layers_array[i] != current_layer_full_address)) {// case insentetive searches.
                         match = true;
                         //If the matched layer is inside a locked group (layerset), unlock the group first.
                         layer.parent.allLocked ? layer.parent.allLocked = false : null;
                         layer.allLocked ? layer.allLocked = false : null;
                         done_layers_array.push(current_layer_full_address);// ensure we don't process layer again. Push does not work in IE5/Win, I don't care :)
                         activeDocument.activeLayer = layer;// select matching layer
                         var chosen_action = chosen_actions_array[i];
                         if (chosen_action != 'none') {
                              doAction(chosen_action,'toms ps cbg actions 7 4 10');// run the action.
                    } else {
                         match = false;
               }// end of looping layer processor.
               // end of if match
// Done iterating through layers to find a match, return result.
     return match;
// Display an alert to let the user know which layers were successfully amended:
var msg = '';
for (var i = 0; i < done_layers_array.length; i++) {
     msg += done_layers_array[i] + '\n';
alert ('These are the layers that were amended:\n' + msg + '\ndone_layers_array.length = ' + done_layers_array.length + '.');
// isCorrectVersion - check for Adobe Photoshop CS2 (v9) or higher
function isCorrectVersion() {
     if (parseInt(version, 10) >= 9) {
          return true;
     else {
          alert('This script requires Adobe Photoshop CS2 or higher.', 'Wrong Version', false);
          return false;
// isOpenDocs - ensure at least one document is open
function isOpenDocs() {
     if (documents.length) {
          return true;
     else {
          alert('There are no documents open.', 'No Documents Open', false);
          return false;
// hasLayers - ensure that the active document contains at least one layer
function hasLayers() {
     var doc = activeDocument;
     if (doc.layers.length == 1 && doc.activeLayer.isBackgroundLayer) {
          alert('The active document has no layers.', 'No Layers', false);
          return false;
     else {
          return true;
// showError - display error message if something goes wrong
function showError(err) {
     if (confirm('An unknown error has occurred.\n' +
          'Would you like to see more information?', true, 'Unknown Error')) {
               alert(err + ': on line ' + err.line, 'Script Error', true);
// test initial conditions prior to running main function
if (isCorrectVersion() && isOpenDocs() && hasLayers()) {
     try {
          // suspend history for CS3 (v10) or higher
          if (parseInt(version, 10) >= 10) {
               activeDocument.suspendHistory('Find Layer', 'main()');
          // just run main for CS2 (v9)
          else {
               main();
     catch(e) {
          // don't report error on user cancel
          if (e.number != 8007) {
               showError(e);
Cheers,
Tom B
aka runninghead

Similar Messages

Maybe you are looking for

  • POPUP after selecting button in ALV

    Hello everyone. I have an ALV (called with FM 'REUSE_ALV...') with a gui status of its own. I added a new button that must popup a window with information on some variables i just ended calculating. I allready tried using 'call screen' and the comman

  • Selfservice option is not coming up in Home workcenter in portal

    Hi Experts, The following 'Self Service views' are not available in the path in portal Home ==>Self-Services==> Self-Services Overview action i have taken 1) Set the evryone group permission in system admininstration. Is this issue related to uploadd

  • Suppress default namespace in extract() function

    How can I avoid that Oracle includes the target namespace of my schema as the default namespace when using the EXTRACT function? E.g., select xmlelement("XmlData", xmlagg(extract(tx.transmission, '/Transmission/Item'))) from transmissions tx returns

  • Wifi not displaying even thought wifi network is available.

    i installed lan drivers related to my laptop version hp 15 r204tu. even after that wifi icon is not displaying in my laptop.Please help me in this issue.. Note: recently i changed the os from win 7 ultimate to win 7 professional. Earlier it is fine.

  • How to open Excel Sheet using JSP?

    Hi Dear, I want to open Excel Sheet in client browser, How to do this using JSP? If it is possible to open, client can make the changes in the sheet if he saves those changes, those changes must reflect on server. So pl. tell me how to do this? Thank