11 Replies Latest reply on Jun 25, 2016 2:50 PM by velimh1

    Watch Folder

    vdiaz761098 Level 1

      Hello,

       

      Is there a way to have Photoshop watch a folder for new images and run some actions on the newly added files - after which removing the original from that folder.

       

      I need to automate the follwoing:

      Image is added to watch folder

      Photoshop

      1. Detects new image
      2. Opens image
      3. Runs actions
      4. Saves to a new directory

      File is deleted from watch folder.

       

      I am on Mac 10.7 and have Automator at my disposal. I'm also familiar with scripting but not specifically for Photoshop so I prefer scripting would be the last resort.

       

      Any help or guidance is greatly appreciated.

       

      Thank you!

       

      V

        • 2. Re: Watch Folder
          vdiaz761098 Level 1

          Hey Paul,


          Thanks for the reply. I tried following the short tutorial but noted two things:

          1. The jsx file in the tutorial -- what do I add to that file? Doesn't seem there is any explanation.

          2. The tutorial calls for AppleScript Utility application which no longer ships with OS X latter versions. I don't have this installed.

           

          I manged to have Automator run the task whith a folder action but as I mentioned, there is nothing is the jsx file so nothing really happens.

           

          Any other links I can take a look at?

           

          Thanks,

           

          V

          • 3. Re: Watch Folder
            Paul Riggott Level 6

            I don't have any more leads but I have put together an example that might work for you (Should work with Windows and Mac).

            First place this BRIDGE script in the correct folder..

             

            PC: Edit - Preferences - Startup Scripts

            Mac: Adobe Bridge menu - Preferences - Startup Scripts

             

            At the bottom click the "Reveal Button"

            this will open the folder where the script should be placed.

            Close and restart Bridge.

            Accept the new script.

             

            To use :

            Navigate to the folder you want to use as your HOT Folder

            Select -> Hot Folder - Start Hot Folder from the menu bar.

            This will create a navbar at the bottom of Bridge with one button for you to stop the process.

            If Photoshop was closed it will open it and place the current folder name in a variable in Photoshops memory.

             

             

            //The Hot Folder will be the folder where you run the script.
            //You should be able to use bridge as normal.
            if( BridgeTalk.appName == "bridge" ) {  
            var newMenuHF = new MenuElement( "menu", "Hot Folder", "after Help", "hotFolder" );
            var runHotFolder= new MenuElement( "command", "Start Hot Folder", "at the end of hotFolder" , "hotFolderxx" );
            }
            runHotFolder.onSelect = function () { 
            var thisFolder = encodeURI(Folder(app.document.presentationPath));
            var cmd = "$.setenv('HotFolder','" +thisFolder+ "');";
            var bt = new BridgeTalk();
            bt.target = "photoshop";
            bt.body = cmd; 
            bt.send();
            processHotFolder = function(){
                /* files to look for */
            if(Folder(thisFolder).getFiles(/\.(jpg|tif|psd|cr2,nef)$/i).length <1) return;
            if (BridgeTalk.getStatus("photoshop") == "IDLE"){
            bt.target = "photoshop";
            bt.body = "var PShotFolder = " + PShot.toSource() + "; PShotFolder();"; 
            bt.send();
                }
            }
            BottomBar = app.document.navbars.filesystem.bottom;
            BottomBar.height = 30;
            BottomBar.visible = true;
            BottomBar.bu1 = BottomBar.add ('button',[5,5,300,25],'Stop Hot Folder');
            id = app.scheduleTask( "processHotFolder()", 2000, true ); 
            BottomBar.bu1.onClick=function(){
                app.cancelTask (id);
               BottomBar.visible = false;
                }
            function PShot(){
            var SCRIPTS_FOLDER =  decodeURI(app.path + '/' + localize("$$$/ScriptingSupport/InstalledScripts=Presets/Scripts"));
            var hotFile = new File(SCRIPTS_FOLDER + "/PShotFolder.jsx");
            $.evalFile (hotFile);
                }
            };
             
            


            This above script calls a Photoshop script if Photoshop is not busy and there are files to be processed.

             

            Save the follow Photoshop script in the applications Presets/Scripts folder.

            Make changes to the script as required for your work flow!!

            Save the script as PShotFolder.jsx as this is the name the Bridge script will be calling.

             

             

            #target Photoshop
            main();
            function main(){
            if($.getenv('HotFolder') == null){
            alert("Please re-start the Hot Folder in Bridge!");
            return;
            }    
            var hotFolder = Folder($.getenv('HotFolder'));
            //create a couple of folders if they do not exist
            var ProcessedFolder = Folder(hotFolder +"/Processed");
            if(!ProcessedFolder.exists) ProcessedFolder.create();
            var OriginalsFolder = Folder(hotFolder +"/Originals");
            if(!OriginalsFolder.exists) OriginalsFolder.create();
            //get a list of files in the hot folder
            var fileList = hotFolder.getFiles(/\.(jpg|tif|psd|cr2,nef)$/i);
            //This is where all the work is done
            for(var z in fileList){
            //Add your own code to suit your needs
            //Example code ....
            //open each file
            open(fileList[z]);
            var Name = decodeURI(app.activeDocument.name).replace(/\.[^\.]+$/, '');
            //run an action ?
            //app.doAction('atn name', 'atnSet name');
            //resize
            FitImage( 1024, 600 );
            //save processed file
            var saveFile = File(ProcessedFolder +"/" + Name + ".psd");
            SavePSD(saveFile);
            //close file
            app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
            //move file to Originals folder
            fileList[z].rename(File(OriginalsFolder + "/" + fileList[z].name));
                }
            }
            function SavePSD(saveFile){ 
            psdSaveOptions = new PhotoshopSaveOptions(); 
            psdSaveOptions.embedColorProfile = true; 
            psdSaveOptions.alphaChannels = true;  
            psdSaveOptions.layers = true;  
            activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE); 
            }
            function FitImage( inWidth, inHeight ) {
             if ( inWidth == undefined || inHeight == undefined ) {
              alert( "FitImage requires both Width & Height!");
              return;
             }
             var desc = new ActionDescriptor();
             var unitPixels = charIDToTypeID( '#Pxl' );
             desc.putUnitDouble( charIDToTypeID( 'Wdth' ), unitPixels, inWidth );
             desc.putUnitDouble( charIDToTypeID( 'Hght' ), unitPixels, inHeight );
             var runtimeEventID = stringIDToTypeID( "3caa3434-cb67-11d1-bc43-0060b0a13dc4" ); 
             executeAction( runtimeEventID, desc, DialogModes.NO );
            }
            
            
             

             

             

            Hope this will be of use.

            1 person found this helpful
            • 4. Re: Watch Folder
              lsavazzi Level 1

              Hi, did you ever find a solution for this? I'm looking to do the same.

               

              Let me know,

              Luca

              • 5. Re: Watch Folder
                flysi3000 Level 1

                This looks like it would work perfectly for what I'm trying to do, but I can't seem to make it actually launch the target script. The Hot Folder menu item is added, I can start the Hot Folder, which then triggers Photoshop CC to launch, but then that's as far as it gets. I also am not familiar enough with ESTK to do any useful debugging, so I can't tell where it's failing. I basically copy/pasted your scripts exactly, with the exception that I named my target script differently, and changed that filename accordingly in the Bridge script.

                 

                Any help would be super useful!

                • 6. Re: Watch Folder
                  Chris---57 Level 1

                  This tutorial is great and works well with CS6 and Windows 7-64 !

                  Nice work
                  But beware: the hotfolder must be named "HotFolder"... That's perhaps it doesnt work ;o)

                  (I first called mine "watchfolder" after reading that any opened one in Bridge is active)
                  By the way, if anyone could help me by changing the end of the Photoshop script into "save as EPS" with options "Maximum JPEG" and "8-bit tiff" it would be great! Thank you in advance

                  Chris

                  • 7. Re: Watch Folder
                    samtotem Level 1

                    This worked great. I'm not that good with Scripts, but even I made it work. One question is, how would I get it to output Save for web jpegs?

                    • 8. Re: Watch Folder
                      Philip Cord Level 4

                      You would replace the SavePSD function with:-

                       

                      function SaveForWeb(saveFile,jpegQuality) {
                      var sfwOptions = new ExportOptionsSaveForWeb(); 
                         sfwOptions.format = SaveDocumentType.JPEG; 
                         sfwOptions.includeProfile = false; 
                         sfwOptions.interlaced = 0; 
                         sfwOptions.optimized = true; 
                         sfwOptions.quality = jpegQuality;
                      activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);
                      };
                      
                      

                       

                      Then change line 29 SavePSD(saveFile);

                      to SaveForWeb(saveFile,80);

                      80 being the quality you can change to your requirements.

                      • 9. Re: Watch Folder
                        samtotem Level 1

                        Thanks for that. Do I need to change line 28 too?

                         

                        1. var saveFile = File(ProcessedFolder +"/" + Name + ".psd");


                        Also,Its not moving the original file to the original folder folder so just keeps going on a loop. What Have I messed up


                        Thanks


                        Sam

                        • 10. Re: Watch Folder
                          Philip Cord Level 4

                          Yes, change the psd to jpg and you should be good to go.

                          • 11. Re: Watch Folder
                            velimh1 Level 1

                            I am using CS5 in OSX 10.11.5 and looking to get the script working. I think the issue is with setenv not being supported.

                            I have tried setting the environment value with Envpane with HotFolder as the name and "+thisFolder+" as the value without luck.

                             

                            There seems to have been other ways to do setenv with launchctl but it seems that due to security related changes none of these workarounds are anymore available to use, I am looking elsewhere to getting myself a hotfolder to run actions from.