2 Replies Latest reply on Jun 15, 2012 11:08 AM by dgolberg

    Clearing the actions panel and loading an action set using a script.

    Dylan Colon

      I've been trying to figure out how to do this now for two days straight, I'm still completely stuck and can't manage to do it. Scriptlistener shows nothing for the "Clear actions" and "Load actions" menu items when the function is called in both CS5 and CS3 and both JS and VBS.

       

      Does anyone here have a solution? Any scripts?

       

      Thank you so much.

        • 1. Re: Clearing the actions panel and loading an action set using a script.
          Paul Riggott Level 6

          This should help...

           

           

          //get a list of all actionSets
          var actionList =getActionSets();
          //remove all actionSets
          for(var d in actionList){
           unLoadAction(actionList[d]);
           }
          //Load your new actionSet
          app.load(File("/c/actions/myNewAtionset.atn"));
          function getActionSets() { 
          cTID = function(s) { return app.charIDToTypeID(s); }; 
            var i = 1; 
            var sets = [];  
            while (true) { 
              var ref = new ActionReference(); 
              ref.putIndex(cTID("ASet"), i); 
              var desc; 
              var lvl = $.level; 
              $.level = 0; 
              try { 
                desc = executeActionGet(ref); 
              } catch (e) { 
                break;
              } finally { 
                $.level = lvl; 
              } 
              if (desc.hasKey(cTID("Nm  "))) { 
                var set = {}; 
                set.index = i; 
                set.name = desc.getString(cTID("Nm  ")); 
                set.toString = function() { return this.name; }; 
                set.count = desc.getInteger(cTID("NmbC")); 
                set.actions = []; 
                for (var j = 1; j <= set.count; j++) { 
                  var ref = new ActionReference(); 
                  ref.putIndex(cTID('Actn'), j); 
                  ref.putIndex(cTID('ASet'), set.index); 
                  var adesc = executeActionGet(ref); 
                  var actName = adesc.getString(cTID('Nm  ')); 
                  set.actions.push(actName); 
                } 
                sets.push(set); 
              } 
              i++; 
            } 
            return sets; 
          }; 
          function unLoadAction(aSet){
          var desc = new ActionDescriptor(); 
          var ref = new ActionReference(); 
          ref.putName( charIDToTypeID( "ASet" ), decodeURI(aSet)); 
          desc.putReference( charIDToTypeID( "null" ), ref ); 
          executeAction( charIDToTypeID( "Dlt " ), desc, DialogModes.NO );
          };
          
          
           
          • 2. Re: Clearing the actions panel and loading an action set using a script.
            dgolberg Level 1

            If you want to add or delete only specific actions, try this:

             

            delAction("actionName"); //Delete a specific action based on its name
            app.load(File(actionPath + "Action.atn")); //Load the action based on it's name from a pre-specified path
            
            function delAction(aName) {
                var idDlt = charIDToTypeID( "Dlt " );
                var desc1 = new ActionDescriptor();
                var idnull = charIDToTypeID( "null" );
                var ref1 = new ActionReference();
                var idASet = charIDToTypeID( "ASet" );
                ref1.putName( idASet, aName );
                desc1.putReference( idnull, ref1 );
                executeAction( idDlt, desc1, DialogModes.NO );
            }