20 Replies Latest reply on Jul 8, 2010 5:24 PM by TreXiaNos

    CS UI

    Ghoulfool Level 1

      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?

        • 1. Re: CS UI
          Paul Riggott Level 6
          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.radiobutton0.value=true;
          win.center(); 
          win.show();
          

          You need to set the value for one of the radiobuttons first.

          • 2. Re: CS UI
            Michael L Hale Level 5

            Paul has a script that will clean up the CSUIB output. That might help make it more useful http://www.ps-scripts.com/bb/viewtopic.php?f=10&t=2580

             

            But to answer your main question, radiobuttons need to be in a container like a group or panel for them to work like radiobuttons( you can only select one at a time ). If they are not in a group they act like checkboxes( you can select any/all buttons )

            1 person found this helpful
            • 3. Re: CS UI
              runninghead

              Dude! I'm working on the same thing!

               

              If someone can tell me how to insert code in to a forum post I'll show you what I've got so far

               

              Cheers,

               

              Tom B

              • 4. Re: CS UI
                Paul Riggott Level 6

                Click on the double chevrons (next to the smiley), select Syntax Highlighting - Plain. this will create an area where you can paste your code into.

                Also an explanation of what you want to achieve and I'm sure you will get some examples.

                • 5. Re: CS UI
                  runninghead Level 1

                  Thanks Paul...here goes:

                   

                  // 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 (info@runninghead.com)
                  // 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: Make the Go button work!
                  
                  // 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 = "lt to st stitching action";
                  var last_match = null;
                  
                  var item;
                  
                  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',
                  'muzzle'
                  );
                  
                  var actions_array = new Array(
                  'Choose an action to run...',
                  'lt to st stitching action',
                  'lt to st outer hairs action',
                  'lt to furry action',
                  'make sketchy lt',
                  'add ticking crap lp',
                  'none'
                  );
                  
                  var ddl_array = new Array();// The array of drop down lists.
                  
                  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 dropdwon menus:
                  for(var i = 0; i < standard_layers_array.length; i++) {
                       ddl_array[i] = win.main_panel.group2.add('dropdownlist', undefined, actions_array[i]); 
                       for (var j = 0; j < actions_array.length; j++) {
                            ddl_array[i].add('item', "" + actions_array[j]); 
                            ddl_array[i].selection = actions_array[0] ;//Make the first item in list appear instead of a blank
                            }
                       }
                  
                  //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
                  
                  var myActions = "sometext"; 
                  var myActionSelection = actions_array[0]; 
                  {//commented out
                  //win.dropdownlist = win.main_panel.group2.add("dropdownlist", undefined,"test"); 
                  
                  //~ var item;
                  //~ for (var i=0,len=actions_array.length;i<len;i++) {
                  //~  win.main_panel.group2.add ('item', "" + actions_array[i]);      
                  //~ }; 
                  
                  //~ win.dropdownlist.onChange = function() { 
                  //~    //Save the selected value in a variable to be used later 
                  //~    myActions = actions_array[parseInt(this.selection)]; 
                  //~    }; 
                  
                  }
                  
                  //~ for (var i=0,len=app.fonts.length;i<len;i++) 
                  //~   {item = win.btnPnl.dropdown.add ('item', "" + app.fonts[i].name); 
                  //~       
                  //~ }; 
                  //~ win.btnPnl.dropdown.onChange = function(){ 
                  //~    //Save the selected value in a variable to be used later 
                  //~    myActionSelection = app.fonts[parseInt(this.selection)].name; 
                  //~    }; 
                  
                  //~ myDlg.closeBtn.onClick = function() {
                  //~   this.parent.close(1);
                  //~ }
                  
                  //Go button:
                  win.buttons_group.goBtn.onClick = function() {
                        var name = ddl_array[2].selection;
                        //alert(name);
                      this.parent.close(); 
                  }; 
                  
                  // Cancel button:
                  win.buttons_group.cancelBtn.onClick = function() { 
                  //~     alert("String Options is " +  myActions + "\n" + 
                  //~           "My action selection is " + myActionSelection);  
                      this.parent.close(); 
                  }; 
                   
                  
                  //Make the first item in list appear instead of a blank
                  //win.dropdownlist.selection = win.dropdownlist.items[0] ;
                  //win.btnPnl.dropdown.selection = win.btnPnl.dropdown.items[0] ;
                  
                  win.show();     
                  win.center();     // move to center before
                  
                  //~      var ret = win.show();  // dialog display
                  //~      if (1 == ret) {     // if  "Open" button clicked.
                  //~           alert ('Open Button Clicked');
                  //~      }
                  
                  
                  // ============================================================================
                  
                  
                  ///////////////////////////////////////////////////////////////////////////////
                  // main - main function
                  ///////////////////////////////////////////////////////////////////////////////
                  function main(name) {
                       // prompt for layer name (first run)
                       if (!name) {
                            //var name = "stitching";
                            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 = "lt to st stitching action";
                  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, name);
                            
                            // repeat find if layer not found
                            if (!match) {
                                 
                                 main(name);
                                 
                            }
                       }
                  
                  
                  ///////////////////////////////////////////////////////////////////////////////
                  // findLayer - iterate through layers to find a match
                  ///////////////////////////////////////////////////////////////////////////////
                  function findLayer(ref, name) {
                       // declare local variables
                       var layers = ref.layers;
                       var len = layers.length;
                       var match = false;
                       
                            // iterate through layerstack to find a match
                            for (var i = 0; i < len; i++) {
                                 var layer = layers[i];
                                 
                                 if (layer.typename == 'LayerSet') {// If it's a layerset, go in one level and carry on.
                                      
                                 match = findLayer(layer, name);
                                 
                                 } else {// This must be a real layer...
                                 
                                      // test for matching layer
                                      var current_layer_full_address =  (layer.parent.name.toLowerCase() + "." + layer.name.toLowerCase());
                  
                                      if ((layer.name.toLowerCase() == name.toLowerCase()) && (done_layers_array[i] != current_layer_full_address)) {// case insentetive searches.
                                           match = true;
                                      } else {
                                           match = false;
                                           }
                                      
                                      if (match) {// Only run on successful match.
                                           //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
                                           doAction(chosen_action,"toms ps cbg actions 7 4 10");// run the axction.
                                      }
                                 
                                 // 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);
                            }
                       }
                  }
                  
                   
                  

                   

                  It's anembarrassing mess now but I think it's worth perfecting

                  • 6. Re: CS UI
                    Paul Riggott Level 6

                    This might give you a start....

                    // 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 (info@runninghead.com)
                    // 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: Make the Go button work!
                    // 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 = "lt to st stitching action";
                    var last_match = null;
                    var item;
                    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',
                    'muzzle'
                    );
                    var actions_array = new Array(
                    'Choose an action to run...',
                    'lt to st stitching action',
                    'lt to st outer hairs action',
                    'lt to furry action',
                    'make sketchy lt',
                    'add ticking crap lp',
                    'none'
                    );
                    var ddl_array = new Array();// The array of drop down lists.
                    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 dropdwon menus:
                    for(var i = 0; i < standard_layers_array.length; i++) {
                         ddl_array[i] = win.main_panel.group2.add('dropdownlist', undefined, actions_array[i]); 
                         for (var j = 0; j < actions_array.length; j++) {
                              ddl_array[i].add('item', "" + actions_array[j]); 
                              ddl_array[i].selection = actions_array[0] ;//Make the first item in list appear instead of a blank
                              }
                         }
                    //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
                    var myActions = "sometext"; 
                    var myActionSelection = actions_array[0]; 
                    {//commented out
                    //win.dropdownlist = win.main_panel.group2.add("dropdownlist", undefined,"test"); 
                    //~ var item;
                    //~ for (var i=0,len=actions_array.length;i<len;i++) {
                    //~  win.main_panel.group2.add ('item', "" + actions_array[i]);      
                    //~ }; 
                    //~ win.dropdownlist.onChange = function() { 
                    //~    //Save the selected value in a variable to be used later 
                    //~    myActions = actions_array[parseInt(this.selection)]; 
                    //~    }; 
                    }
                    //~ for (var i=0,len=app.fonts.length;i<len;i++) 
                    //~   {item = win.btnPnl.dropdown.add ('item', "" + app.fonts[i].name); 
                    //~       
                    //~ }; 
                    //~ win.btnPnl.dropdown.onChange = function(){ 
                    //~    //Save the selected value in a variable to be used later 
                    //~    myActionSelection = app.fonts[parseInt(this.selection)].name; 
                    //~    }; 
                    //~ myDlg.closeBtn.onClick = function() {
                    //~   this.parent.close(1);
                    //~ }
                    //Go button:
                    win.buttons_group.goBtn.onClick = function() {
                          var name = ddl_array[2].selection;
                          //alert(name);
                       win.close(1); 
                       // 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);
                              }
                         }
                    }
                    }; 
                    // Cancel button: nothing needed as close is the default!
                     
                     
                    //Make the first item in list appear instead of a blank
                    //win.dropdownlist.selection = win.dropdownlist.items[0] ;
                    //win.btnPnl.dropdown.selection = win.btnPnl.dropdown.items[0] ;
                    win.center();     // move to center before
                    win.show();     
                    
                    //~      var ret = win.show();  // dialog display
                    //~      if (1 == ret) {     // if  "Open" button clicked.
                    //~           alert ('Open Button Clicked');
                    //~      }
                    
                    // ============================================================================
                    
                    ///////////////////////////////////////////////////////////////////////////////
                    // main - main function
                    ///////////////////////////////////////////////////////////////////////////////
                    function main(name) {
                         // prompt for layer name (first run)
                         if (!name) {
                              //var name = "stitching";
                              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 = "lt to st stitching action";
                    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, name);
                              
                              // repeat find if layer not found
                              if (!match) {
                                   
                                   main(name);
                                   
                              }
                         }
                    
                    ///////////////////////////////////////////////////////////////////////////////
                    // findLayer - iterate through layers to find a match
                    ///////////////////////////////////////////////////////////////////////////////
                    function findLayer(ref, name) {
                         // declare local variables
                         var layers = ref.layers;
                         var len = layers.length;
                         var match = false;
                         
                              // iterate through layerstack to find a match
                              for (var i = 0; i < len; i++) {
                                   var layer = layers[i];
                                   
                                   if (layer.typename == 'LayerSet') {// If it's a layerset, go in one level and carry on.
                                        
                                   match = findLayer(layer, name);
                                   
                                   } else {// This must be a real layer...
                                   
                                        // test for matching layer
                                        var current_layer_full_address =  (layer.parent.name.toLowerCase() + "." + layer.name.toLowerCase());
                                        if ((layer.name.toLowerCase() == name.toLowerCase()) && (done_layers_array[i] != current_layer_full_address)) {// case insentetive searches.
                                             match = true;
                                        } else {
                                             match = false;
                                             }
                                        
                                        if (match) {// Only run on successful match.
                                             //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
                                             doAction(chosen_action,"toms ps cbg actions 7 4 10");// run the axction.
                                        }
                                   
                                   // 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);
                         }
                    }
                    
                    
                    
                    • 7. Re: CS UI
                      runninghead Level 1

                      Great! Havn't had a chance to go too far in to it yet but already it's working. This gets more absorbing every day.

                      Just got a book on PS scripting and it doesn't even mention the UI so I'll be here again tomorrow.

                      Cheers,

                      Tom B

                      • 8. Re: CS UI
                        runninghead Level 1

                        Here's where it's at now- anyone else got progress?

                         

                        // 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 (info@runninghead.com)
                        // 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;
                        
                        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',
                        'muzzle'
                        );
                        
                        var actions_array = new Array(
                        'Choose an action to run...',
                        'lt to st stitching action',
                        'lt to st outer hairs action',
                        'lt to furry action',
                        'make sketchy lt',
                        'add ticking crap lp',
                        'none'
                        );
                        
                        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].name = 'ddl_' + [i];
                             dropdownlist_array[i].selection = actions_array[0] ;//Make the first item in list appear instead of a blank
                             // 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 len = layers.length;
                             var match = false;
                             
                                  // iterate through layerstack to find a match
                                  for (var i = 0; i < len; 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());
                                       
                                            if ((layer.name.toLowerCase().indexOf (name, 0)!=-1) && (done_layers_array[i] != current_layer_full_address)) {// case insentetive searches.
                                                 match = true;
                                            } else {
                                                 match = false;
                                                 }
                                            
                                            if (match) {// Only run on successful match.
                                                 //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
                                                 doAction(chosen_action,'toms ps cbg actions 7 4 10');// run the action.
                                            }
                                       
                                       }// 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);
                                  }
                             }
                        }
                        
                         
                        

                        • 9. Re: CS UI
                          Ghoulfool Level 1

                          Runninghead,

                           

                          I tried your script but it barfs at line 79

                          (Syntax error)

                           

                          ->   var win = new Window (ui); // new window object with UI resource

                           

                          I'm running CS2

                          • 10. Re: CS UI
                            runninghead Level 1

                            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 (info@runninghead.com)
                            // 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

                            • 11. Re: CS UI
                              Michael L Hale Level 5

                              I don't use resource strings to create dialogs so I don't know why but it doesn't work for me either in CS2. The dialog works in CS3 or higher.

                              • 12. Re: CS UI
                                Paul Riggott Level 6

                                The problem is in Group 2 it has a spurious comma..

                                 

                                orientation: "column", \
                                //should be ...
                                orientation: "column" \
                                
                                • 13. Re: CS UI
                                  runninghead Level 1

                                  Try replacing the relevant section with this.

                                  It'll still 'barf' because it doesn't work yet but I'd be interested to hear whether the following  will get past the CS version issues.

                                   

                                  var ui = // fake 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:\"cance\"} },' +
                                            '}' +
                                       '}';
                                  
                                       var win = new Window (ui); // new window object with fake UI resource
                                  

                                   

                                  Asap, I'll put in some recursive function code up front to gather an array of all layers first.

                                  Then I'll try to lose the current recursive stuff as far as possible (don't really understand it!).

                                  I'm afraid the shallow foundations of my coding knowledge are leading me in circles.

                                  • 14. Re: CS UI
                                    Paul Riggott Level 6

                                    Try this....

                                    var ui = // fake 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:\"cance\"} },' +
                                              '}' +
                                         '}';
                                         var win = new Window (ui); // new window object with fake UI resource
                                         win.center();
                                         win.show();
                                    
                                    
                                    • 15. Re: CS UI
                                      runninghead Level 1

                                      Thanks Paul, spurious comma removed + tidied up a bit.

                                      Changed 'cance' to 'cancel' to in the cancel button line.

                                      I've corrected the order of 'centre' and 'show' and left them 'til after the code that alters the ui content.

                                       

                                      Will post a complete rewrite (hopefully) by the end of the day (GMT offset=0).

                                      I've high hopes this will sort the script out once and for all.

                                      Found a great snippet for Illustrator scripting in a book and will adapt it for use.

                                      Should be perfect for you, Ghoulfool.

                                      Tom B

                                      • 16. Re: CS UI
                                        runninghead Level 1

                                        Ok- going a bit code-blind staring at this thing for too long, here's the latest, would work well if only it would loop properly!

                                         

                                         

                                        // 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 (info@runninghead.com)
                                        // 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
                                        // ============================================================================
                                        // 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;//'default var declaration in line 31';
                                        
                                        var myTitle = 'Customize your Processing :)';
                                        
                                        var done_layers_array = new Array();
                                        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 visible_layers_array = new Array();// an array of arrays, [0] = layer name, [1] = parent, [2] = visibility, [3] = locked value.
                                        
                                        // 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 ui = // fake dialog resource object, used to allow script to run in PS versions as old as CS2.
                                             '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 fake UI resource
                                             
                                             // Reset all text in the main_panel titles and buttons:
                                             win.main_panel.text = myTitle;
                                        //----------------------------------------------------------
                                        
                                        // 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);
                                                  }
                                             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".
                                        }; 
                                        
                                        // All done creating window content, move to center before showing:
                                        win.center();
                                        win.show();
                                        
                                        function getaddress(obj) {
                                             var a = obj.parent.name;
                                             var b = obj.parent.parent;
                                             if (b != activeDocument) {
                                                  a += '.' + (getaddress(obj.parent));
                                                  }
                                             return a;
                                             }
                                        
                                        // Recursive function to loop through all layers, determining name, visibility and locked status and building an array of the results:
                                        function listVisible(ref){
                                             for (var i = 0; i<ref.length; i++) {
                                                  if (ref[i].visible && ref[i].name != 'Background') {
                                                       if (ref[i].typename == 'LayerSet') {// layer is really a Layerset.
                                                            //visible_layers_array.push('group: ' + listVisible(ref[i].layers));
                                                            listVisible(ref[i].layers);
                                                            } else {// ordinary visible layer.
                                                                 var this_address_string = ref[i].name + '.' + getaddress(ref[i]);// use another recursive function (nested, eek!) to get parents.
                                                                 var address_array = this_address_string.split('.');// split the address up in to an array delimeted by the dots so we can reverse it.
                                                                 address_array.reverse();// reverse the address array (it was compiled backwards).
                                                                 var this_address_string_reversed = address_array.join('.');// rejoin the array in to a usable string, complete with dots.
                                                                 // Now put the results in to an array object so we get a stored database of all eligible layers and their details:
                                                                 new_entry = new Array(ref[i], this_address_string_reversed.toLowerCase(), ref[i].visible, ref[i].allLocked);
                                                                 // Make an array of these array objects:
                                                                 visible_layers_array.push(new_entry);
                                                            }
                                                       }
                                                  }
                                        }
                                        
                                        function layer_done_check(layer_address, loop_digit) {
                                             if (layer_address == done_layers_array[loop_digit]){
                                                  return true;
                                             } else {
                                                  return false;
                                             }
                                        }
                                        
                                        function layername_matches(layername, search_string) {
                                             if (layername.indexOf (search_string, 0)!=-1){
                                                  return true;
                                             } else {
                                                  return false;
                                             }
                                        }
                                        
                                        
                                        function execute_actions() {
                                             
                                        for (var i = 0; i < visible_layers_array.length; i++) {// for loop 1 (i)
                                             // 0 = layer name, 1 = layer path, 2 = layer visibility, 3 = layer locked.
                                                  var layer = visible_layers_array[i][0];
                                                  var layername = visible_layers_array[i][0].name.toLowerCase()
                                                  var layer_address =  visible_layers_array[i][1].toLowerCase();
                                                  var search_string = standard_layers_array[i];
                                             
                                             for (j = 0; j < standard_layers_array.length; j++){//for loop 1.1 (j)
                                                  if (layername.indexOf (standard_layers_array[j], 0)!=-1) {
                                                       var matched = true;
                                                       } else {
                                                            var matched = false;
                                                       }
                                                  } //
                                             
                                             for (k = 0; k < done_layers_array.length; k++){// for loop 1.2 (k)
                                                  if (layer_address == done_layers_array[k]) {
                                                            var done = true;
                                                            trace(done);
                                                       } else {
                                                            var done = false;
                                                       }
                                                  }//
                                             
                                             if ((!done) && (matched)) {// if not already done and matched to a standard layer name, process.
                                                       alert('the layername \"'+ layername + '\" matches standard_layers_array[' + i + '] aka \"' + search_string + '\"and\nYes: process ' + layername + ' with the action ' + chosen_actions_array[i] + '\n\n' + 'done_layers_array = ' + done_layers_array);
                                                       done_layers_array.push(layer_address);// ensure we don't process layer again. Push does not work in IE5/Win, I don't care :)
                                                  }
                                             
                                             }// end of for loop 1 (i)
                                             
                                        }// end of execute_actions function.
                                        
                                        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('listVisible', 'main()');
                                        //~           }
                                        //~           // just run main for CS2 (v9)
                                        //~           else {
                                        
                                                       // We're good to go, call the recursive function:
                                                       listVisible(activeDocument.layers);
                                                       // Call it:
                                                       execute_actions();
                                                       
                                                       // Provide feedback:
                                                       var list_msg = 'visible_layers_array (' + visible_layers_array.length + ') :\n\n ';
                                                       for (var i = 0; i < visible_layers_array.length; i++) {
                                                            list_msg += visible_layers_array[i][0].name + '\n\n';
                                                            }
                                                            alert (list_msg);
                                                            //}
                                             }
                                             
                                             catch(e) {
                                                  // don't report error on user cancel
                                                  if (e.number != 8007) {
                                                       showError(e);
                                                  }
                                             }
                                        
                                        
                                        
                                        • 17. Re: CS UI
                                          Ghoulfool Level 1

                                          Runninghead, I'm sorry to say I get an error at line 90 undefined is not an object.. As much as I appriciate your efforts to rewrite the script, I think trying to make this code work on another machine - without knowing the specifications of the your super seekret photoshop files is a bit like finding a needle in a haystack. I'll keep looking for other scripts to work out how the ui elements function. Cheers.

                                          • 18. Re: CS UI
                                            runninghead Level 1

                                            Yeah, guess it's not that helpful to others when things get too specific like that.

                                            I've learnt a lot doing this though, I should think enough to accomplish the task of your initial post, if not, sadly, my own problem

                                            Anyway, made any progress? I'll do my best to help you if you update this thread, otherwise I'll keep my own coding issues out of it until my scripts sorted. Sorry for muddying the waters.

                                            Good luck

                                            • 19. Re: CS UI
                                              Michael L Hale Level 5

                                              runninghead, I see at least one problem with your last posted code. In the actions dropdown onChange you have

                                              chosen_actions_array[i] = this.selected.text;
                                              

                                              I think it should be

                                              chosen_actions_array[i] = this.selection.text;
                                              

                                              That may not completely fix your code but this.selected.text throws an error for me.

                                              • 20. Re: CS UI
                                                TreXiaNos

                                                thanks