• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Watch Folder

New Here ,
Nov 05, 2012 Nov 05, 2012

Copy link to clipboard

Copied

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

TOPICS
Actions and scripting

Views

23.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Valorous Hero ,
Nov 05, 2012 Nov 05, 2012

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 05, 2012 Nov 05, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 06, 2012 Nov 06, 2012

Copy link to clipboard

Copied

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);
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.rename(File(OriginalsFolder + "/" + fileList.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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 16, 2014 Jul 16, 2014

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 13, 2014 Nov 13, 2014

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 11, 2015 Jun 11, 2015

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 12, 2015 Jun 12, 2015

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 14, 2015 Jun 14, 2015

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 14, 2015 Jun 14, 2015

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 24, 2016 Jun 24, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 04, 2019 Mar 04, 2019

Copy link to clipboard

Copied

Hi I found an edited version of this script, however it still gets stuck in a loop as it doesn't move the file to the originals folder on line 43

 

//This script is called by the Bridge script "Bridge Hot Folder.jsx"

#target Photoshop

main();

function main(){

if($.getenv('HotFolder') == null){

alert("Please re-start the Hot Folder in Bridge!");

return;

}   

try{

var hotFolder = Folder(decodeURI($.getenv('HotFolder')));

if(!hotFolder.exists){

    alert("Can't find hot folder!"+ "\n" + hotFolder);

    return;

    }

//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|psb|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);

var Name = decodeURI(app.activeDocument.name).replace(/\.[^\.]+$/, '');

//run an action ?

//app.doAction('atn name', 'atnSet name');

app.doAction('All_Prep', 'Car_Final_Prep');

 

//resize

// disabled // FitImage( 1024, 600 );

 

//save processed file

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

SaveTIFF(saveFile);

//close file

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

//move file to Originals folder

fileList.rename(File(OriginalsFolder + "/" + fileList.name));

    }

}catch(e){alert(e + "\n" + e.line);}

}

function SaveTIFF(saveFile){

tiffSaveOptions = new TiffSaveOptions();

tiffSaveOptions.embedColorProfile = true;

tiffSaveOptions.alphaChannels = false; 

tiffSaveOptions.layers = false; 

activeDocument.saveAs(saveFile, tiffSaveOptions, 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 );

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 04, 2019 Mar 04, 2019

Copy link to clipboard

Copied

I didn't look into, but remember it's piece (Bridge and Phosothop) script.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 04, 2019 Mar 04, 2019

Copy link to clipboard

Copied

Yes i have the other script in bridge.

It seems like its an error and photoshop can't move the file under OSX

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 04, 2019 Mar 04, 2019

Copy link to clipboard

Copied

This is the line that does't work. On OSX

fileList.rename(File(OriginalsFolder + "/" + fileList.name));

Any ideas?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 04, 2019 Mar 04, 2019

Copy link to clipboard

Copied

How does it fail to work? Does the folder hotfolder Originals contain a file with that name so the move rename fails. Is the disk full , does the move fail because of access right.  Why does the sove fail? Start there.

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 04, 2019 Mar 04, 2019

Copy link to clipboard

Copied

No the file doesn't exist in the Originals folder.

The disk isn't full,

The script creats the folders and can write to the Processed folder.

Not sure what you mean by 'sove'

Is it an old way of doing things that no longer works in PS 2018 or maybe the move comand can't be done this way in PS on a mac?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 04, 2019 Mar 04, 2019

Copy link to clipboard

Copied

sove was a typo it should have been move a file system file rename move.

The statement is for the Originals folder does that  folder get created? If it does are any files moved into it?  The Processed folder is where the document should be saved after the action is played. Then the original file is moved from the hotfolder to the Originals folder. Which you state is where the problem is. Its an Mac OS file system move not a Photoshop feature. Adobe JavaScript ScriptingSupport plug-in  using Your Mac file system.

//save processed file

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

SaveTIFF(saveFile);

//close file

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

//move file to Originals folder

fileList.rename(File(OriginalsFolder + "/" + fileList.name));

The original file should be moved out of the hotfoldet into its subfolder Originals....

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 04, 2019 Mar 04, 2019

Copy link to clipboard

Copied

To identify a problem, you first need to make sure that the rename () function works in MacOS when moving a file to another folder.
Create and run such a script.
File and destination folder must exist.

var file = new File("~/Desktop/_HotFolder/some file.psb");

var folder = new Folder("~/Desktop/_HotFolder/Originals");

if (file.rename(folder.fullName + "/" + file.name))

    alert("OK!");

else

    alert(file.error, "", true);

 
If everything is in order, then the problem is different.
I remembered that I had encountered errors in renaming a file if a folder with a file is open, for example, in another program (in my case, the XnView viewer), and it also tries to do something with the file, for example, to read it.

I solved this problem by making several rename attempts at a short interval.

Try this version of the script.

//This script is called by the Bridge script "Bridge Hot Folder.jsx" 

#target Photoshop 

main(); 

function main(){ 

if($.getenv('HotFolder') == null){ 

alert("Please re-start the Hot Folder in Bridge!"); 

return; 

}     

try{ 

var hotFolder = Folder(decodeURI($.getenv('HotFolder'))); 

if(!hotFolder.exists){ 

    alert("**** can't find hot folder!"+ "\n" + hotFolder); 

    return; 

    } 

//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|psb|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); 

var Name = decodeURI(app.activeDocument.name).replace(/\.[^\.]+$/, ''); 

//run an action ? 

//app.doAction('atn name', 'atnSet name'); 

app.doAction('All_Prep', 'Car_Final_Prep'); 

 

//resize 

// disabled // FitImage( 1024, 600 ); 

 

//save processed file 

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

SaveTIFF(saveFile); 

//close file 

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 

//move file to Originals folder 

////////////////////////////////////////////////

var ok = false;

for (var ii = 0; ii < 10; ii++)

    {

    if (!fileList.rename(File(OriginalsFolder + "/" + fileList.name))) 

        {

        $.sleep(300);

        }

    else

        {

        ok = true;   

        break;

        }

    } 

if (!ok || fileList.error)

    {

    alert("can't rename file: " + fileList.name);

    return;

    }

////////////////////////////////////////////////

    }

}catch(e){alert(e + "\n" + e.line);} 

function SaveTIFF(saveFile){  

tiffSaveOptions = new TiffSaveOptions(); 

tiffSaveOptions.embedColorProfile = true;  

tiffSaveOptions.alphaChannels = false;   

tiffSaveOptions.layers = false;   

activeDocument.saveAs(saveFile, tiffSaveOptions, 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 ); 

}



Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 05, 2019 Mar 05, 2019

Copy link to clipboard

Copied

r-bin

The top script

gave me an I/O error

The bottom

'can't rename file'

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 05, 2019 Mar 05, 2019

Copy link to clipboard

Copied

jackdaw_1066  написал(а)

r-bin

The top script

gave me an I/O error

And the folder to where the file is renamed is on the same disk as the file itself?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 05, 2019 Mar 05, 2019

Copy link to clipboard

Copied

Yes, same folder

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 05, 2019 Mar 05, 2019

Copy link to clipboard

Copied

It is necessary that someone else who works on a Mac confirms that this way of file renameing does not work on a Mac, in order not to return to this question.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 16, 2019 Apr 16, 2019

Copy link to clipboard

Copied

I confirm 'rename' doesn't work on Macintosh.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 05, 2019 Mar 05, 2019

Copy link to clipboard

Copied

Read this.How to move files using app.system()?

Substitute your file and folder names.
Note the spaces in the file name.

Does it work for you?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines