14 Replies Latest reply on May 19, 2015 8:47 AM by c.pfaffenbichler

    Help with my script

    Ramesh Devalla

      Hi there,

      When i run the script second time on same file it's getting executed. how to ignore this execution. I just want to execute only once on one file please help me.

        • 1. Re: Help with my script
          c.pfaffenbichler Level 9

          Please clarify.

           

          When i run the script second time on same file it's getting executed.

          Does this mean you actually start the Script but do not want it to be executed? (Then why trigger it?)

          Or does the Script in one normal run perform a task twice that you want performed only once?

           

          One could use various means (metadata, a preference file, …) to signify how a certain file should be handled.

          But depending on future processing needs and whether several computers are involved this might necessitate different approaches.

          • 2. Re: Help with my script
            Ramesh Devalla Level 1

            I thank you for your assistance. Here is the script want this script should be executed only on .jpg format file.

            thanks in advance


            var d=app.activeDocument;

            var cp = activeDocument.path;

            var tempname;  

            var folder1 = Folder(cp + '/');

            var CFName = app.activeDocument.name;

            var SFCP = new File(folder1 + '/' + CFName.substring(9));

            var saveTIFF= new TiffSaveOptions();

            saveTIFF.alphaChannels = false;

            saveTIFF.annotations = false;

            saveTIFF.byteOrder = ByteOrder.MACOS;

            saveTIFF.embedColorProfile = true;

            saveTIFF.imageCompression = TIFFEncoding.NONE;

            saveTIFF.layerCompression = LayerCompression.RLE;

            saveTIFF.layers = true;

            saveTIFF.saveImagePyramid = false;

            saveTIFF.spotColors = false;

            saveTIFF.transparency = false;

             

             

            activeDocument.saveAs(new File(SFCP , saveTIFF), saveTIFF);

             

             

            //app.activeDocument.close(SaveOptions.SAVECHANGES);

            • 3. Re: Help with my script
              c.pfaffenbichler Level 9

              That should be easy enough, just wrap it in an if-clause that checks for the ending "jpg":

              if (app.documents.length > 0) {
              var thedoc = app.activeDocument;
              if (thedoc.name.match(new RegExp('jpg|jpeg$','i')) != null) {
                alert ("is a jpg")
                }
              else {alert ("no jpg")}
              };
              
              

              edited

              • 4. Re: Help with my script
                Ramesh Devalla Level 1

                Thanks a lot It's working.

                • 5. Re: Help with my script
                  c.pfaffenbichler Level 9

                  You’re welcome.

                  • 6. Re: Help with my script
                    Ramesh Devalla Level 1

                    Hi,

                    One more issue with Script it's working fine with Mac OS but when i try to run in Windows getting Error 8800.

                    Thanks

                    • 7. Re: Help with my script
                      c.pfaffenbichler Level 9

                      At which line does it fail?

                      What are the file and folder names?

                      • 8. Re: Help with my script
                        Ramesh Devalla Level 1

                        Line:35

                        C:\Users\ramu\Desktop\165322\12345678.ABCDEFGHIJ.DEFG.jpg

                        Capture.PNG

                        • 9. Re: Help with my script
                          c.pfaffenbichler Level 9

                          Could you please post the complete Script in its current form?

                          • 10. Re: Help with my script
                            Ramesh Devalla Level 1

                            var d=app.activeDocument;

                            var cp = activeDocument.path;

                            var tempname;   

                            var folder1 = Folder(cp + '/'); 

                            var CFName = app.activeDocument.name;

                            //Turn display dialogs off 

                            /*app.displayDialogs = DialogModes.NO;

                            if (app.documents.length=0) {

                            var thedoc = app.activeDocument;

                            if (thedoc.name.match(new RegExp('jpg','i')) != null) {

                            alert ("is a jpg")

                              var SFCP = new File(folder1 + '/' + CFName.substring(9));

                              }

                              else

                            {

                              alert ("no jpg")}

                               //var SFCP = new File(folder1 + '/' + CFName);

                            };*/

                            var SFCP = new File(folder1 + '/' + CFName.substring(9));

                            var saveTIFF= new TiffSaveOptions();

                            {

                            saveTIFF.alphaChannels = false;

                            saveTIFF.annotations = false;

                            saveTIFF.byteOrder = ByteOrder.IBM;

                            saveTIFF.embedColorProfile = true;

                            saveTIFF.imageCompression = TIFFEncoding.NONE;

                            saveTIFF.jpegQuality = 12;

                            saveTIFF.layerCompression = LayerCompression.RLE;

                            saveTIFF.layers = true;

                            saveTIFF.saveImagePyramid = false;

                            saveTIFF.spotColors = false;

                            saveTIFF.transparency = false;

                            //saveTIFF,pixelOrder = Interleaved;

                            }

                            activeDocument.saveAs(new File( SFCP , saveTIFF),saveTIFF);

                             

                             

                            //app.activeDocument.close(SaveOptions.SAVECHANGES); 

                            • 11. Re: Help with my script
                              d1g1talphyre Level 1

                              I changed line 35 to:


                                   activeDocument.saveAs(SFCP ,saveTIFF);


                              reason being, the saveAs needs a new file name, which you'd already provided earlier in the code.  Also a location.  the second part needs your save file type options.  which you have set also, the rest of it is as follows:

                               

                              saveAs (saveIn [, options] [, asCopy] [, extensionType])


                                   ,asCopy = saving as a copy, true false flag.

                                   , extensionType = this refers to upper or lower case extention.  example: Extension.LOWERCASE


                              here is a whole example:

                                   activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);


                              hope that helps Ramesh

                               

                              • 12. Re: Help with my script
                                c.pfaffenbichler Level 9

                                You don’t seem to have fully understood what I meant by

                                wrap it in an if-clause

                                 

                                // 2015, use it at your own risk;
                                if (app.documents.length>0) {
                                var thedoc = app.activeDocument;
                                var theJpg = new RegExp('jpg|jpeg','i');
                                if (thedoc.name.match(theJpg) != null) {
                                var d=app.activeDocument;
                                var cp = activeDocument.path;
                                var CFName = app.activeDocument.name;
                                var SFCP = new File(cp + '/' + CFName.replace(theJpg, "tif"));
                                var saveTIFF = new TiffSaveOptions();
                                saveTIFF.alphaChannels = false;
                                saveTIFF.annotations = false;
                                saveTIFF.byteOrder = ByteOrder.IBM;
                                saveTIFF.embedColorProfile = true;
                                saveTIFF.imageCompression = TIFFEncoding.NONE;
                                saveTIFF.layerCompression = LayerCompression.RLE;
                                saveTIFF.layers = true;
                                saveTIFF.saveImagePyramid = false;
                                saveTIFF.spotColors = false;
                                saveTIFF.transparency = true;
                                activeDocument.saveAs(SFCP,saveTIFF);
                                }
                                else
                                {
                                alert ("no jpg")}
                                };
                                

                                 

                                Keep in mind that this would overwrite an existing file of that name at that location, though!

                                • 13. Re: Help with my script
                                  d1g1talphyre Level 1

                                  instead of overwriting, add another if statement checking with .exists  that would avoid the overwrite.

                                  • 14. Re: Help with my script
                                    c.pfaffenbichler Level 9

                                    Indeed, but the original poster should be able to do that themselves.