22 Replies Latest reply on Jul 31, 2014 7:43 AM by timlogochair

    Save in file location?

    mschuenke

      Hey all. I'm really confident with actions, but new to scripting. I'm looking write something to 'save as' a file into the open file's location. So whatever file I'm working on, when I run the action or script it will save to the current folder. I haven't found a way to do this with actions so I want to know if I can with scripts.

       

      For example, on the desktop I have a test1 folder and test2 folder. I can record an action to save an open image from test1 to test1, but then open images from test2 go back into test1. My work around right now is another action (file/automate/batch) to run the saving action and open the dialog box where I can direct it where to save.

       

      I appreciate any help.

      -Matt

        • 1. Re: Save in file location?
          JJMack Most Valuable Participant

          Most actions that are batched do not open files an only need a Save As if the need to set the file type to be saved.  When the do contain a Save As step these steps are often over road by the batch option.

           

          Input file are from a folder and optionally image file in lower levels, or open file ,or files selected in the bridge, or imported.

           

          Output files may be saved by the action being batch but most to the time it the batch processor that saves the output files. Over riding save as commands or overwriting the input file using the save on close option or saved into an output folder set by the user. For the batch processor can set output file name using user set options.  It hard to name output file well in actions for they cant not use  logic  to retrieve document names and generate output names based on document names.

          BATCH.jpg

           

          A script can do just about anything you want to do. One can open files from where ever and save file any where it has write athority.

          • 2. Re: Save in file location?
            c.pfaffenbichler Level 9

            Does this help?

            // 2013, use it at your own risk;

            #target photoshop;

            if (app.documents.length > 0) {

            var thedoc = app.activeDocument;

            // getting the name;

            var docName = thedoc.name;

            try {

            var basename = docName.match(/(.*)\.[^\.]+$/)[1];

            }

            catch (e) {

            var basename = docName;

            };

            //getting the location;

            try {

            var docPath = thedoc.path;

            }

            catch (e) {

            var docPath = "~/Desktop";

            };

            // psd options;

            psdOpts = new PhotoshopSaveOptions();

            psdOpts.embedColorProfile = true;

            psdOpts.alphaChannels = true;

            psdOpts.layers = true;

            psdOpts.spotColors = true;

            // check if file of that name exists;

            if (File(docPath+"/"+basename+".psd").exists == true) {

            var theConfirm = confirm ("file exists; overwrite?", true, "file exists");

            if (theConfirm == true) {

            thedoc.saveAs((new File(docPath+"/"+basename+".psd")),psdOpts,false);

            }

            }

            else {

            //save psd:

            thedoc.saveAs((new File(docPath+"/"+basename+".psd")),psdOpts,false);

            }

            };

            //that’s it; thanks to xbytor;

            • 3. Re: Save in file location?
              mschuenke Level 1

              Thanks for the reply. I understand how the batch works, as that is how I have been saving files. Mine is set to use open files and save to a folder, which is where I hit the choose option and select the folder where the open files live. Looks like scripts are the answer because I need to have the save destination be a variable. Something like save to open file location, does that exist in a script?

              • 4. Re: Save in file location?
                JJMack Most Valuable Participant

                I can think of two scripts that are available that you may want to check out. The Image Processor script that ships with Photoshop found under menu File>Scripts>Image Processor...  The second one you need to download and install. Download is on Russell Browns Web Site. The script name is Image Processor Pro... its a plug-in script once installed you will find it under menu File>Automate>Image Processor Pro.... These scripts can process collection of files from various sources. From the Bridge, Open Documents in Photoshop, or files In a folder or tree.  Output files can be saved to the same location of the document being process associated file.

                ippd.jpg

                • 5. Re: Save in file location?
                  mschuenke Level 1

                  Thanks JJ. I tried out Russell's Processor and it seems like that'll work! Do you happen to know if you can have it overwrite files? Right now I have an open tif and when I tell it to save a tif in the same location with just the document name, it puts a _01 and the end of the tif instead of overwriting it.

                  • 6. Re: Save in file location?
                    mschuenke Level 1

                    But strangely it doesn't put a _01 after a png file I had open and set it to save in the same location with the same name. Though it still didn't overwrite the original.

                    • 7. Re: Save in file location?
                      JJMack Most Valuable Participant

                      The Image Processors scripts are coded to always save new files. If a file exists it wants to save it will add a suffix sequence number and if that file exist it will keep incrementing the suffix sequence number till it finds one that does not exists and then save a new file with that name.

                      • 8. Re: Save in file location?
                        JJMack Most Valuable Participant

                        mschuenke wrote:

                         

                        But strangely it doesn't put a _01 after a png file I had open and set it to save in the same location with the same name. Though it still didn't overwrite the original.

                        Are you sure you had the save check box checked in the png tab.  You  can set up taps to save file types and turn off the save by un-checking the tab's save option.  Such a tab will have a *prefix.note the tif and psd tabs in this screen capture. Their save option is un-checked.

                        ippd.jpg

                        • 9. Re: Save in file location?
                          JJMack Most Valuable Participant

                          mschuenke wrote:

                          Do you happen to know if you can have it overwrite files?

                          While is not possible to have the script overwrite the original files it easy for you to do.  Just use the script to create a new folder and not save in sub-folders and only save a one image file of any given file type not different sizes of the same file type, set output filename to be the same as the original without a suffix. The original source files set must not contain duplicate filename with different extensions like a.jpg and a.tif for that would create a duplicate output filename which would get a serial number added.

                           

                          Once you create the new files in a new folder you can move them to the old folder replacing the original.

                          • 10. Re: Save in file location?
                            Michael L Hale Level 5

                            I tried out Russell's Processor and it seems like that'll work! Do you happen to know if you can have it overwrite files?

                            You could try making a feature request to xbytor. He is the person that is maintaining that script. His email is on Dr. Brown's web site where you downloaded Image Processor Pro. Even if he doesn't want to add that feature he may be able to tell you how to modify the script so you can have a local version that overwrites existing files.

                             

                            If you want to try to modify the script yourself I think if you find the line( around line 8892 )

                            outfile = ImageProcessor.createUniqueFileName(outfile, saveOpts._saveForWeb);

                             

                            and add this line right above that line

                            if(outfile.exists) outfile.remove();

                             

                            the script will always overwrite.


                            • 11. Re: Save in file location?
                              JJMack Most Valuable Participant

                              Just remember if you do delete and replace files you could possible loose something you can not recovered except from backup which you may on may not have.  An other approach would be to rename the original file for possible deletion. Like rename original.ext to original.ext.4deletion. Neither way is ideal for both ways have a problem.

                               

                              Remember if in a folder there are different file type with like name for example original.jpg and original.PSD and a Image Processor Pro run was setup to save PSD files for image files in that folder.  When the jpeg file is processed the like named psd file would be deleted or renamed by the mod made.. Then a new originalname.PSD would be saved with the modifications made to the jpeg document.  Then that new originalname.PSD would then be processes by the script for that file would be in the list of files to process. So the new originalname.PSD would be opened and processed deleted or renamed and a new new originalname.pds with a different modification would be saved.

                               

                              What you wind up with using the delete mod is your original.jpg and an originalname.PSD That may be nothing like you wanted and your original layered PSD file was deleted never processed and lost. If you used the rename approach the script should fail during the second rename when it tries to rename the new originalname.PSD to originalname.PSD.4deletion for that file now exists.

                               

                              If the file list has a different sort order where the psd file is processed first the Layered PSD file still gets deleted and and replaced with the modifications made to the jpeg document a file you wanted and you still have your original jpg file and the original psd file is still lost.  The rename mod should still bomb on the second rename.

                               

                              There is no easy solution for often you save different file type for an image and you may have then a single folder. Paul's picture processor has a an source image file type filter you may be able to use his processor to filter a source file type extension and save the same file type. Maybe even replacing source files. I have not tested it.

                              Picture Processor II dialog:

                              ppII.jpg

                               

                              I just did a quick test and Paul's Picture Processor can be used to filter file types and replace the filtered files.

                              Source folder = target folder jpg to jpg test dialog settings

                              yesreplace.jpg

                              http://www.ps-bridge-scripts.talktalk.net/

                              Download Zip File

                              bridge support

                              Download Zip File

                              Message was edited by: JJMack

                              • 12. Re: Save in file location?
                                Michael L Hale Level 5

                                JJMack wrote:

                                 

                                Just remember if you do delete and replace files you could possible loose something you can not recovered except from backup which you may on may not have.

                                The same thing applies to overwritting the file. Because the OP asked how to have the script overwrite an existing file I assumed they were aware to that risk.

                                 

                                If they don't want to run the risk of replacing a file then just leave the script as it is now. It already renames if the file exists.

                                • 13. Re: Save in file location?
                                  mschuenke Level 1

                                  Yes I will definitely request that feature. I'm not concerned at all about overwriting the file. I always have everything I work on backed up on a server so I'm not risking losing anything I can't get back. I'd rather not save to a seperate folder and move everything back over because this is a process that I'll go through 50 times a day and want to cut out any extra steps possible. Right now I'm just going through manually after the save and deleting all of the original files and removing the _01 from the newly saved files.

                                   

                                  From a glance it doesn't look like that picture processor can work from open files, so that wouldn't work for my need.

                                   

                                  Thanks for telling me those mods to the script Michael. That looks like it would work, but I'm getting an error when I try to open up the script to add those in. Could someone add them in and attach the file? I'd appreciate it.

                                  • 14. Re: Save in file location?
                                    JJMack Most Valuable Participant

                                    I agree leave the script as is for its safe. It easy to create new file and the move the new files to replace old ones. if that is what you want and Paul's script does not fit your requirements. I would not like the script with the delete mod on my machine. My memory being what it is....

                                    • 15. Re: Save in file location?
                                      Michael L Hale Level 5

                                      ... I'm getting an error when I try to open up the script to add those in.

                                      Are you using the ExtendScript Toolkit editor that ships with Photoshop to edit the script? What is the error message?

                                      • 16. Re: Save in file location?
                                        mschuenke Level 1

                                        Yes I am using ExtendScript Toolkit. This is the error message:

                                         

                                        Error in

                                        Line 2999: s =

                                        String(xmp.*::RDF.*::Description.*::ISOSpeedRatings.*::Seq.*::li);

                                        Syntax Error

                                         

                                        Also I've already heard back from xbytor so I should be able to get it to overwrite once I can get into the script to edit it. Xbytor said:

                                         

                                        Open up the script an search for this line:
                                          // There is a dupe. Make unique by adding _## to the basename

                                         

                                        Right before that line add this line:

                                          return file;

                                        • 17. Re: Save in file location?
                                          xbytor2 Level 4

                                          I emailed mschuenke this patch.

                                           

                                          Open up the script an search for this line:
                                            // There is a dupe. Make unique by adding _## to the basename

                                           

                                           

                                          Right before that line add this line:

                                            return file;

                                           

                                          The file is probably write-protected on the Scripts folder. You''' need to change file permissions to edit the file.

                                           

                                          Edit: Missed the previous post.

                                           

                                          I don't see that line where the error occurs in the rev of IPP that I have installed. Email me your version so I can figure out what's going on.

                                          • 18. Re: Save in file location?
                                            xbytor2 Level 4

                                            It looks like you have a beta version, somehow. The current rev is:

                                            http://www.russellbrown.com/images/tips_downloads/Services_Installer_2.3.1.zip

                                            • 19. Re: Save in file location?
                                              mschuenke Level 1

                                              Yes 2.3.1 is the version I have installed. I was able to get around the error. If I try to open the script with Extendscript it give me the error, but if I right-click and click edit, it opens up just fine. Not sure why. There aren't any write protections on it. I tried dragging a copy to my desktop to do it from there and got the same results.

                                               

                                              I added that line of script and it isn't overwriting still. Do I need to remove the // There is a dupe. Make unique by adding _## to the basename line? As that's what I don't want it to do.

                                              • 20. Re: Save in file location?
                                                xbytor2 Level 4

                                                The function that has the problematic xml (psx.getXMPValue) can be removed as it is not used. The version I am using is a earlier one that did not have some of the psx functions.

                                                 

                                                I have applied the patch to the 2.3.1 code and it has tested succesfully.

                                                 

                                                I'll email you the modified rev.

                                                1 person found this helpful
                                                • 21. Re: Save in file location?
                                                  mschuenke Level 1

                                                  Thanks! Got it and it works great.

                                                  • 22. Re: Save in file location?
                                                    timlogochair Level 1

                                                    Where can I get this modified script that will overwrite files instead of naming sequentially?