FORUMS: list search recent posts

Photoshop script help with Error: cannot open the file because the open options are incorrect

COW Forums : Adobe Photoshop

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Rob Stemm
Photoshop script help with Error: cannot open the file because the open options are incorrect
on Nov 27, 2008 at 1:00:05 am

I'm trying to iterate through a folder of images, open each one of them, duplicate them into another photoshop file and close the individual image. This javascript code works great on a PC (Photoshop CS3), but when I run it on our macs (Photoshop CS3) I will receive the following error on random images. "Error: Cannot open the file because the open options are incorrect" Does anyone know how to solve this problem? I've read about possibly setting the OpenDocumentType but have not seen an example anywhere. This error will sometimes occur after loading in one image or sometimes after 20 images. Sometimes I run it on the same directory multiple times all with various points of error. Sometimes every images is loaded. The images I am loading are PNG files. Any help would be much appreciated. Sample code is below.

//CODE BELOW
//allows the user to select an folder full of images

var inputFolder = Folder.selectDialog("Select a folder that contains the files you want added as layers.");

var fileList = inputFolder.getFiles();

var tempRef = app.open(tempName);

for (var i = 0; i < fileList.length; i++)

{

var tempName = fileList[i];

var tempStringName = fileList[i].toString();

//used to check if the file in the directory does in fact contain the .png extension
var reducedFileName = tempStringName.substring(tempStringName.lastIndexOf("/")+1);

if(reducedFileName.substring((reducedFileName.length - 4),(reducedFileName.length)) != ".png" || reducedFileName.substring((reducedFileName.length - 4),(reducedFileName.length)) != ".PNG")

{

//setting reference to opened docuement PNG file
//This seems to be the section throwing the error. Surrounding with Try Catch revealse the Error noted above

var tempRef = app.open(tempName);

//setting a tempName variable to the PNG file name
var tempName = app.activeDocument.name;

//setting reference to the active layer in the file
var graphicLayer = app.activeDocument.activeLayer;

//setting the PNG layer name to the PNG file
tempRef.layers[0].name = tempName;

//duplicating the image onto the opened Photoshop file
tempRef.layers[0].duplicate(backRef);

//closing the original PNG file without saving
tempRef.close(SaveOptions.DONOTSAVECHANGES);

}
}


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]