I am trying to make a script for photoshop in js, and I want to add an image to a new layer. The proble is that I simply cant find the jpg (teszt_fekvő.jpg), evendough it is in the same folder. Here is the code:
var newDoucument=app.documents.add(1080, 1080, 300, "New Document", NewDocumentMode.RGB);
var layers = newDoucument.artLayers;
var newLayer = layers.add();
newLayer.name = "New Layer";
var imagePath = new File("~/teszt_fekvő.jpg");
if(imagePath.exists) {
placeFile(imagePath);
} else {
alert("File not found");
}
I have tried absolute filepath, and I am 100% that the name of the file is correct.
imagePath = new File(...)and then you immediate throw that away and overwrite the variable by usingimagePath = File.openDialog(...).Fileis a thin wrapper around the OS's file handling without its own logic, so which OS are you running? Because if it's Windows,~is not part of a valid path (so your script will silently error out), and if it's MacOS,~is your home directory. One thing you probably want to do is make liberal use oftry { ... } catch (e) { alert(...) }to catch errors. Photoshop scripting is basically an exercise in "do I remember all the best practices from 1998" because of how old the version of JS involved is =)