Basis for hot folder?

Photoshop Script Snippets - Note: Full Scripts go in the Photoshop Scripts Forum

Moderators: Tom, Kukurykus

Paul MR

Basis for hot folder?

Post by Paul MR »

Code: Select allvar hotFolder = function(event){
var toDoFolder = new Folder(app.document.presentationPath+ '/Processing');
   if(!toDoFolder.exists)  toDoFolder.create();
     if ((event.type == 'loaded') && (event.object instanceof Document)) {
         app.document.deselectAll();
         var sels = app.document.getSelection ("jpg");
         if(sels.length>0){
         for(var a in sels){
             sels[a].moveTo(toDoFolder);
             }
         }
         return { handled: false };
         }
  return { handled: false };
}
app.eventHandlers.push( { handler: hotFolder } );
Mike Hale

Basis for hot folder?

Post by Mike Hale »

You are so much better at Bridge scripting than I that I'm not sure I understand what this does.

It looks like it adds a event listener to Bridge. What fires the event?
Paul MR

Basis for hot folder?

Post by Paul MR »

Every time a file is added or removed from the folder the "Loaded" event is triggered. So all it is doing at the moment is to create a Folder and any jpg that is dropped into the hot folder is immediatly moved to the processing folder.
Paul MR

Basis for hot folder?

Post by Paul MR »

A step further...
Any file of the selected type will be moved.
A flag file is created, if it exists Photoshop should be Processing (This needs to be written)
If it does not exist a message is sent to Photoshop to run an action (This action should run the Photoshop script)
Text files with a list of filename(s) are created in the Processing folder these files should be opened by the Photoshop script when all the text files have been processed they should be removed and the flag file deleted.

The Bridge script.
Code: Select all#target bridge   
if( BridgeTalk.appName == "bridge" ) { 
var newMenuHF = new MenuElement( "menu", "Hot Folder", "after Help", "myHotFolder" );
var hf = new MenuElement( "command", "Start Hot Folder", "at the end of myHotFolder" , "qazw" );
}
hf.onSelect = function () {
     startHotFolder();
     }
function startHotFolder(){
Stop = false;
TopBar = app.document.navbars.filesystem.top;
TopBar.height = 30;
TopBar.visible = true;
TopBar.bu1 = TopBar.add ('button',[5,5,100,25],'Stop');
TopBar.bu1.onClick=function(){
   TopBar.visible = false;
    TopBar.remove( TopBar.children[0] );
    Stop = true;
    }
var toDoFolder = new Folder(app.document.presentationPath+ '/Processing');
var flagFile = new File(toDoFolder + "/toDo.dat");
if(!toDoFolder.exists)  toDoFolder.create();

var hotFolder = function(event){ 
   if ((event.type == 'close') && (event.object instanceof App)) {
      return { handled: !Window.confirm("Are you sure you want to quit?") };
  }
     if ((event.type == 'loaded') && (event.object instanceof Document)) {
         if(Stop) return { handled: true };
         app.document.deselectAll();
         var sels = app.document.getSelection ("jpg, tif, cr2, crw, nef"); //file types to select and move
         if(sels.length>0){
             //A text file is created for each file(s)  moved
             var fList = new File(toDoFolder +"/"+ new Date().getTime()+".txt");
             fList.open("w", "TEXT", "????");
             $.os.search(/windows/i)  != -1 ? fList.lineFeed = 'windows'  : fList.lineFeed = 'macintosh';
         for(var a in sels){
             sels[a].moveTo(toDoFolder);
             fList.writeln(decodeURI(sels[a].name));
                 }
             fList.close();
             //Create a flag file, if exists Photoshop should be processing
             if(!flagFile.exists){
                 flagFile.open('w');
                 flagFile.close();
                 var bt = new BridgeTalk();
                    bt.target = "photoshop";
                    /////////////////////////////////////////////////////////////////////////////////////////
                    // This calls an action to run the Photoshop script
                    // Amend as required
                    bt.body = "doAction('HotFolder', 'Hot Folder');";
                    bt.send(4);
             }
         }
         return { handled: false };
         }
  return { handled: false };
}
app.eventHandlers.push( { handler: hotFolder } );
hotFolder("loaded"); //Deal with any files that exist
}