Copy link to clipboard
Copied
I'm looking for a very simple java script to check file corruption
it should:
1.open a file I send to it (via droplet)
2.if it works > close the file > send the file to a folder like c:/checked/
3.if the open sequence crashes or doesn't work > re launch photoshop
4.mark the file as beeing corrupt or send it to a another folder
I don t know how to move a file via java script without saving
I don t know how I can relaunch ? force-quit photoshop ? is this even possible ?
Regards
Copy link to clipboard
Copied
Why not use the Try......Catch construct so failures to open within the "try" region of code would bail out to the "catch" error routine and then just keep looping. That is what they use in the Image Processor script BTW. Hope that helps
Copy link to clipboard
Copied
Why not use the Try......Catch construct so failures to open within the "try" region of code would bail out to the "catch" error routine and then just keep looping.
Unfortunately, there are types of jpeg corruptions that cause PS to throw up a 'Broke File' dialog in spite of how you open the file or have your DialogModes preferences set. PS just stops cold waiting for user interaction. I'll see if I can locate one of these that I used to test with. The last time I looked at this problem in depth (CS2 or CS3) PS was still misbehaving.
Copy link to clipboard
Copied
xbytor2 > thats the exact problem I'm having. If there is a "wrong" file into my batch, photoshop stop/ crash, is waiting for an action on my side... the whole idea of using photoshop droplets is to do it without me.
Should I parse the files (I have jpegs; png and raws... parsing raws ?)? Would it be better like someone said to use a script that "try catch"? (no idea what it is or how to write this). I also red that photoshop image processing is skipping bad files, is that true ? how could I apply this technique ?
bad file > skip > no crash > process continue running would be even better than the original validation idea
Copy link to clipboard
Copied
Anstellos1 wrote:
xbytor2 > thats the exact problem I'm having. If there is a "wrong" file into my batch, photoshop stop/ crash, is waiting for an action on my side... the whole idea of using photoshop droplets is to do it without me.
Should I parse the files (I have jpegs; png and raws... parsing raws ?)? Would it be better like someone said to use a script that "try catch"? (no idea what it is or how to write this). I also red that photoshop image processing is skipping bad files, is that true ? how could I apply this technique ?
bad file > skip > no crash > process continue running would be even better than the original validation idea
"Unfortunately, there are types of jpeg corruptions that cause PS to throw up a 'Broke File' dialog in spite of how you open the file or have your DialogModes preferences set. PS just stops cold waiting for user interaction. I'll see if I can locate one of these that I used to test with. The last time I looked at this problem in depth (CS2 or CS3) PS was still misbehaving.
xbytor2 if much more of an expert than I am in the script area so will have to defer to him"
I would have to defer to xbytor2 since he is much more of an expert than I in scripting. If the Try....Catch construct does not work, than Image Processor in PS and also accessed by Bridge would fail under the same circumstances since that is the construct that script uses. Interesting
"How would you write that ? Are you saying that if I use this script at the beginning of my photoshop droplets, it won't crash on a bad file and continue looping on the next ?:"
If you want to use the Try...Catch constructs looking at the Image Processor Code from ExtendScript ToolKit (or other script editor) would let you see how it operates. They use the Try...Catch construct in multiple locations in that script.
At the highest level in Image Processor here is the basic code below for the Try...Catch construct with most everything else stripped out.
There are two main steps. One is to set the app.displayDialogs mode to NO. The second is to use the try...catch construct below. The error routine is the catch portion of the code just displays the error code. Then the dialog mode is reinstated to the original settings set by the User. The same construct is used deeper into the code so that would be a source of at least the approach Image Processor uses.
try {
// remember the dialog modes
gSaveDialogMode = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
Code you want to execute goes here
}
// Lot's of things can go wrong
// Give a generic alert and see if they want the details
catch( e ) {
if ( e.number != 8007 ) { // don't report error on user cancel
alert( e + " : " + e.line );
}
}
// restore the dialog modes
app.displayDialogs = gSaveDialogMode;
Copy link to clipboard
Copied
I've logged a Photoshop bug on this issue (#2867052). If someone could please attach a JPEG that I can use to repro...
Copy link to clipboard
Copied
Tom,
I've emailed one to you that might fit the bill....
Copy link to clipboard
Copied
thebestcpu > Im a real beginner at scripts ^^
How would you write that ? Are you saying that if I use this script at the beginning of my photoshop droplets, it won't crash on a bad file and continue looping on the next ?
Copy link to clipboard
Copied
In order to do what you want, you need to drive the process using an external 'macro' program like Autokey on Windows if
you want PS to do image file validation.
The problem is that PS handles differernt kinds of file corruptiion using different mechanisms. Some can be handled/captured
via JS, others can't requiring an app outside of PS to look for a 'Broken File' error dialog and act appropriately.
I got something working years ago when I was having to batch process 10,000+ files over a weekend. Having the entire
process stop at file #124 was a bit of a problem. I was never able to get a technique that worked on the Mac either.
If I had to do something like this again, I would write a perl script and a good jpeg library to validate the files and just avoid PS
altogether. You don't really need to render the images, you just need to parse them.
Another thought is the Bridge API. It may do better error handling and reporting of various types of corruption than PS does.
The rest of the stuff you want to do is relatively easy. Detecting and dealing with corrupt files in JS in PS is known hard problem.
Copy link to clipboard
Copied
I wrote a script as a part of xtools called xscan that scans folders for 'bad' files. Files that can't be opened are logged and optionally moved to
a 'bad' directorty.
http://ps-scripts.cvs.sourceforge.net/viewvc/ps-scripts/xtools/apps/xscan.jsx?revision=1.34
It doesn't get around the odd broken files that I wrote about earlier, but it does everything else.
-X