6 Replies Latest reply: Aug 6, 2012 6:21 AM by ocphotog RSS

    Variables in an action to use in script

    ocphotog Community Member

      I want to duplicate an image, then change the duplicated image name to the original image name with some extra text at the end to make it slightly different.

       

      Example.

       

      Original..    Image123

      Duplicate...  Image123BW. Or Image123BG. etc.

       

      So as not to have to have a separate script for each different text addition I wondered if I can have a variable in the action that can be passed to the script to add to the new document name?

        • 1. Re: Variables in an action to use in script
          c.pfaffenbichler Community Member

          One crude approach might be to have the Action create a Layer of a specific name and have the Script evaluate the activeLayer’s name.

          • 2. Re: Variables in an action to use in script
            ocphotog Community Member

            I tried that and can make a new document with BW for example added but whats the coding I need to replace the  existing document name with the new name?  Thanks!

            • 3. Re: Variables in an action to use in script
              c.pfaffenbichler Community Member

              Please post your current code.

               

              In any case to get the active layer’s name

              app.activeDocument.activeLayer.name

              should work.

              • 4. Re: Variables in an action to use in script
                ocphotog Community Member

                Code to duplicate document:

                 

                **************************************

                var doc = app.activeDocument

                var fname = doc.name.split(".")

                var fname = fname[0]

                var ToneType = 'BW'

                var newDoc = doc.duplicate(fname+ToneType,true)

                 

                 

                //var newDoc = doc.duplicate(fname,true)

                 

                 

                newDoc.flatten();

                 

                **************************************

                I have 3 actions that I want to use the script for. One action to make a B&W (BW), one for Sepia (SP), one for Warm B&W (WBW). If I use the above code it will just duplicate the document with the same name, adding the hardcoded ToneType to the end of the document name. I could make three scripts, one for each, but I thought if I could have a variable (ToneType = 'BW') for example, that would pass to the script then I could only use one script that would change depending on the variable name that was in the action.

                This code will just duplicate the document without the text  COPY  at the end but I need to make one for each ToneType I have. Maybe that's the easiest way but I like to make a script with multiple uses.

                 

                When you suggested that rename the active layer with a specific name, I can rename the background layer to  BW  for example, but at the end I still need to rename the file with the   BW . I can script the part to add the active layer to the document name but can't figure out how to replace the name when the script goes back to Photoshop.  I know something is missing in this code that will replace the active documents name. Just not sure what.

                 

                this is the code for that try:

                //replace name of current document with document name + active layer name

                layerN = activeDocument.activeLayer.name

                var doc = app.activeDocument

                var fname = doc.name.split(".")

                var fname = fname[0]

                 

                app.activeDocument.name = (fname+layerN,true)

                 

                 

                Thanks for any help!

                • 5. Re: Variables in an action to use in script
                  JJMack MVP

                  You can write a Plug-in script that will duplicate the cuuent document with a suffix other then the default "Copy".  When you record an action and use the plug-in script to create the duplicate document with some sufix added to the name you will need to enter the suffix to be used in the script's dialog.  The script coded as a Plug-in will record that setting  into the action step being recorded . When the action is played the script will not display its dialog it will use the setting recorded into the action's step.  In other words the Action steps when played Passes the suffix to be use for each duplicat with sufix step recorded into an action.  During an action you can make many duplicate with different suffixes. Just remember to save and close the dupe created in the action to return the original document before creating the next dup with suffix in the action.

                  • 6. Re: Variables in an action to use in script
                    ocphotog Community Member

                    I understand what you are saying and I think that would be perfect, it's just a bit beyond my limited scripting knowledge at the moment. I assume that when the script is first run in the action it will stop for user input. After that the next time it is run it will use that input to to run the script without stopping. So I could use one script in all the actions and each one could have a different suffix associated with it. Honestly I don't know if I could figure out the correct coding for that. But is sounds like a great option. Could you point me to some resources to do that?

                     

                    Thanks for your help!