Copy link to clipboard
Copied
Hi,
Is there a way to check if the file is supported when loading it ?
I have the following example:
var importFile = new File(imgFolder + fileName);
try{
app.load(importFile);
}catch(e) {
return JSON.stringify({name: e.name, message: e.message});
}
I'm returning the error to another application, but when the file is not supported (for example a broken or invalid format .PNG), then it will pass that try block and the script will continue to execute and is producing another error afterwards.
I'm getting the "cannot parse file" error described on this thread: Could not complete your request because the file-format module cannot parse the file
I need to get pass this error dialog and just return a custom message to another application.
PS. DialogModes.NO is already done.
Thanks in advance,
Jaan
Message was edited by: Jaan Koppe
Copy link to clipboard
Copied
This is a known problem of all versions of PS. There is nothing you can do in PS/JS to get around the problem.
The only solution is to use and external app to recognize the error message pop up and have it select the OK button it displays.
I did something like this using AutoHotKey on Windows. There is probably something similar available on OS X.
After doing the app.load() call, check to see if the activeDocument is different.
This is a problem that Adobe should have fixed a decade ago.
Copy link to clipboard
Copied
Thanks for your reply, yes I looked for other discussion's also and found that its an old problem.
With this particular problem I discovered that the actual file type is JPEG, but the extension is just .png and that's enough to photoshop to not open it.
I managed to solve it to check the actual file type with ImageMagick before sending to photoshop.
Adobe should add some internal try{}catch{} block's to this. When I tried to open the "broken" file, then the ScriptingListener didn't even log it. It get's the log only when the action is successful.
Copy link to clipboard
Copied
When I had to process large batches (10k+) of jpgs, I would run them through IrfanView in batch mode to find the corrupt ones. Using ImageMagick is another reasonable approach to take.