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
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
Copy link to clipboard
Copied
Mark did a short tutorial here for a Mac...
http://www.ps-scripts.com/bb/viewtopic.php?f=16&t=3686&sid=532238dc25b15b4c631f8d80850a3dc4
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
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.
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!
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
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?
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.
Copy link to clipboard
Copied
Thanks for that. Do I need to change line 28 too?
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
Copy link to clipboard
Copied
Yes, change the psd to jpg and you should be good to go.
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.
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 );
}
Copy link to clipboard
Copied
I didn't look into, but remember it's piece (Bridge and Phosothop) script.
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
Copy link to clipboard
Copied
This is the line that does't work. On OSX
fileList
.rename(File(OriginalsFolder + "/" + fileList .name));
Any ideas?
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.
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?
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
The original file should be moved out of the hotfoldet into its subfolder Originals....
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 );
}
Copy link to clipboard
Copied
r-bin
The top script
gave me an I/O error
The bottom
'can't rename file'
Copy link to clipboard
Copied
jackdaw_1066 написал(а)
r-bin
The top script
gave me an I/O error
Copy link to clipboard
Copied
Yes, same folder
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.
Copy link to clipboard
Copied
I confirm 'rename' doesn't work on Macintosh.
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?