6 Replies Latest reply on Jan 19, 2016 1:04 PM by JJMack

    Script to target specific file kinds.

    jafetc

      I need to write a script to only target PNG files. I'd like to run on start up and always flatten PNG files when opening.

        • 1. Re: Script to target specific file kinds.
          JJMack Most Valuable Participant

          On start up of what your system, Photoshop or something  else. Do you want to select a png file or process every png in a folder, path, drive or all drives? You need to describe what you want to do better.

          • 2. Re: Script to target specific file kinds.
            pixxxel schubser MVP & Adobe Community Professional

            Sorry jafetc,

            your question is not clear.

             

            But anyway

            var pngFiles = File.openDialog ("select files","*.png");
            
            

            will show you the open dialog (only png)

             

            and

            app.activeDocument.flatten();
            // or
            pngFiles[counter].flatten();
            
            

            will flatten the active document (or the file with your loop counter).

             

            Perhaps this helps you a little bit.

            Regards

             

            • 3. Re: Script to target specific file kinds.
              jafetc Level 1

              Sorry I guess its a tad unclear. I want to enable the script listener and anytime I open a file if its a PNG I want it to flatten the file. But only PNG files. I work with a ton of PNG files and every single one of them has a layer 0 (our vendor thought it was cute to do that I guess) I have to do this manually and its annoying plus sometimes I forget to flatten and it causes problems if I don't flatten. Such as Blurred edges

              • 4. Re: Script to target specific file kinds.
                jafetc Level 1

                Basically I want to write and if statement. If its a PNG flatten else do nothing.

                • 5. Re: Script to target specific file kinds.
                  JJMack Most Valuable Participant

                  That is not what you want to do, The scriptlistener is a plugin that records action manager script  code for what you do in Photoshop..

                   

                  What I think you want to do is to enable the script event manager,  Once  you do you can set an open event to trigger an action or script to run when you open ad document. You would need to write a simple script to flatten png files you open.  Conditional actions can not test a file type condition the list of conditions is small. The script just needs to test the document's name.  However  You may not want to flatten for that creates a background layer and would remove any transparency your png might have had. You may just want merge down to a single layer that may contain transparency. That script will be more complex to write then just flatten.  If your pngs have no transparenct flatten away.

                  Capture.jpg

                  Capture.jpg