0
votes

So I made a script for Photoshop based on this generator

The important part is

#target photoshop

function main() {
    //  prompt user to select source file, cancel returns null
    var sourceFile = File.openDialog("Select a 1:1 sqaure PNG file that is at least 618x618.", "*.png", false);
    if (sourceFile == null)  { 
        // user canceled
        return;
    }

    var doc = open(sourceFile, OpenDocumentType.PNG);
    if (doc == null) {
        alert("Oh shit!\nSomething is wrong with the file. Make sure it is a valid PNG file.");
        return;
    }

....
}

main();

this allways worked. But when today I wanted to change something in the script (I haven't even started yet and not used it for about 2 weeks) I suddendly only get an error (translated from german):

Error 8000: The file can not be opened since the parameters for opening are incorrect.
Line:764
-> doc = open(sourceFile, OpenDocumentType.PNG);

How can I open a PNG file via a File.Open dialog in a Photoshop script?


I already tried to add the app

var doc = app.open(sourceFile, OpenDocumentType.PNG);

to remove the document type specifier

var doc = open(sourceFile);

or to add this as I saw it in many forums

var doc = open(sourceFile, OpenDocumentType.PNG, undefined);

and variations between them. Nothing helped so far.


For debugging I also added

alert(sourceFile);

before the according line and get e.g.

~/Desktop/Example/originalImage_2000x2000.png

1
To clarify: this provided snippet doesn't work for you? Because it should. Maybe sourceFile is incorrect somehow? Weird characters in path, wrong type..?Sergey Kritskiy
@SergeyKritskiy no none of the provided snipperts work for me they all throw that error messagederHugo
what about making it even more precise? Something like var sourceFile = new File("~/Desktop/test.png"); if (sourceFile.exists) var doc = open(sourceFile, OpenDocumentType.PNG); else alert('file not found');Sergey Kritskiy
@SergeyKritskiy my Pc was quite slow in general and Photshop didn't even open any file anymore. So I just rebooted and the problem went away by itself .. Photshop is back to normal and the script now just runs fine and opens my file ... anyway strange behaviour. Maybe some Adobe process in the background causing trouble? However, thanks for your time!derHugo

1 Answers

0
votes

The problem apparently was with Photshop in general! When I opened Photshop I didn't even get the default view of last opened files etc and actually was not able to open any file ... but never tested this first.

After rebooting the PC and launching Photshop now everything went back to normal and the script just runs fine and as expected.