I have been working on a script to automate the conversion of images (JPG, JPEG, etc) to CMYK. As part of the process I am also converting the images profile, however, even though I am supplying the parameters for what profile I want to use it is still bringing up a dialog box that is preventing the script from running. The dialog box is the Convert Profile dialog box that you would get if you did it manually through Photoshop listing the current working space and the one that you want to convert to. Since I already specified that in the parameters of the command should't it skip right past this? Additionally, the dialog box only appears on some images and not all. From what I can tell it is appearing on images that already have a profile embedded (but I am not positive, I am still testing and trying to figure it out).
It works 90% of the time and then stops for a dialog box on a few files. Any assistance would be helpful.
Following is my script. Please note I am not a scripter/coder and I am only good enough and tenacious enough to find other people's code (that have provided it freely) and modify it to my needs.
//Let's Process CMYK files
//This is the location of the text file that contains the list of directories that images will be prcossed from. This is generated using an Applescript and placed in this directory.
var folderList = File("/Applications/Image Directories/ImageDirectoriesCMYK.txt");
//Uncomment the next line for troublshooting the value of "folderList"
$.writeln (folderList);
//This opens the text file and reads the values into an array
folderList.open('r');
while(!folderList.eof) {
var theDirectoryName = folderList.readln();
//make theDirectoryName equal to the name of the directory that it just read from the array.
//Uncomment the next line to see the value of theDirectoryName for troubleshooting.
$.writeln (theDirectoryName)
//Create the Do you varialbe inputFolder and tell it is a folder with the same name as theDirectoryName
var inputFolder = Folder(theDirectoryName);
//Uncomment the next line to see the value of inputFolder for troublshooting
$.writeln(inputFolder);
//Get a list of all the files in the directory above and put them in an array called "filelist". At this point it has the file name and full path.
var fileList = inputFolder.getFiles (/\.(jpg|jpeg|psd|tif|png|gif|bmp)$/i);
//Uncomment the the next line to see the list of files in "Filelist" for troubleshooting
$.writeln(fileList);
//Next if is for loop that will loop through all the files in "Filelist" and export each to a PDF
for (var i = 0; i < fileList.length; i++) {
if (fileList [i] instanceof File) {
//make "document = the file that we are opening
var document = app.open (fileList [i]);
//make "documentName" the name of the current open file
var documentName = fileList [i]
//make "shortname" the name of the file minus the path and extenstion
var shortName = documentName.name.substr(0,documentName.name.lastIndexOf("."));
//uncomment the next line to see/debug the value of "shortName"
$.writeln(shortName);
$.writeln (theDirectoryName);
//make "modSaveLoc" the path where we are going to save the files
var modSaveLoc = theDirectoryName.replace ('3_To Be Verified', '4_Verified High res/')
$.writeln(modSaveLoc);
//make "saveLocation" the path + name and extension of the file
var saveLocation = (modSaveLoc + shortName + ".psd");
// Uncomment the next line to see the value of saveLocationfor troubleshooting
$.writeln(saveLocation);
//Resize the Image to 300 DPI
document.resizeImage(null,null,300,ResampleMethod.NONE);
//Convert the image to CMYK
document.changeMode(ChangeMode.CMYK);
//convert the image to our working profile.
document.convertProfile("SWOP2013C3_CRPC5.icc" , Intent.RELATIVECOLORIMETRIC);
//call the function to save the document
SavePSD(saveLocation)
//Close the currently open image
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
//var extension = ".complete"
//documentName.rename((i+1).toString()+extension);
//fileName = filepath.Base(fileList [i]);
//Get the file name witout the extension
var myFileName = documentName.name.substr(0,documentName.name.lastIndexOf("."));
//Get the file extension
var myFileExt = documentName.name.substr(documentName.name.lastIndexOf(".") ,documentName.name.length);
//Write the value of myFileName
$.writeln(myFileName);
//Write the value of myFileExt
$.writeln(myFileExt);
//Rename the file worked on so that it is not picked up again and processed
documentName.rename(myFileName + myFileExt + ".complete");
}
}
}
//Close the folderlist that it is reading
folderList.close();
//Let's process Grayscale Now
//This is the location of the text file that contains the list of directories that images will be prcossed from. This is generated using an Applescript and placed in this directory.
var folderList = File("/Applications/Image Directories/ImageDirectoriesGrayscale.txt");
//Uncomment the next line for troublshooting the value of "folderList"
$.writeln (folderList);
//This opens the text file and reads the values into an array
folderList.open('r');
while(!folderList.eof) {
var theDirectoryName = folderList.readln();
//make theDirectoryName equal to the name of the directory that it just read from the array.
//Uncomment the next line to see the value of theDirectoryName for troubleshooting.
$.writeln (theDirectoryName)
//Create the Do you varialbe inputFolder and tell it is a folder with the same name as theDirectoryName
var inputFolder = Folder(theDirectoryName);
//Uncomment the next line to see the value of inputFolder for troublshooting
$.writeln(inputFolder);
//Get a list of all the files in the directory above and put them in an array called "filelist". At this point it has the file name and full path.
var fileList = inputFolder.getFiles (/\.(jpg|jpeg|psd|tif|png|gif|bmp)$/i);
//Uncomment the the next line to see the list of files in "Filelist" for troubleshooting
$.writeln(fileList);
//Next if is for loop that will loop through all the files in "Filelist" and export each to a PDF
for (var i = 0; i < fileList.length; i++) {
if (fileList [i] instanceof File) {
//make "document = the file that we are opening
var document = app.open (fileList [i]);
//make "documentName" the name of the current open file
var documentName = fileList [i]
//make "shortname" the name of the file minus the path and extenstion
var shortName = documentName.name.substr(0,documentName.name.lastIndexOf("."));
//uncomment the next line to see/debug the value of "shortName"
$.writeln(shortName);
$.writeln (theDirectoryName);
//make "modSaveLoc" the path where we are going to save the files
var modSaveLoc = theDirectoryName.replace ('3_Grayscale', '4_Verified Grayscale/')
$.writeln(modSaveLoc);
//make "saveLocation" the path + name and extension of the file
var saveLocation = (modSaveLoc + shortName + "_Grayscale" + ".psd");
// Uncomment the next line to see the value of saveLocationfor troubleshooting
$.writeln(saveLocation);
//Resize the Image to 300 DPI
document.resizeImage(null,null,300,ResampleMethod.NONE);
//Convert the image to CMYK
document.changeMode(ChangeMode.GRAYSCALE);
//convert the image to our working profile.
document.convertProfile("SWOP2013C3_CRPC5.icc" , Intent.RELATIVECOLORIMETRIC);
//call the function to save the document
SavePSD(saveLocation)
//Close the currently open image
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
//var extension = ".complete"
//documentName.rename((i+1).toString()+extension);
//fileName = filepath.Base(fileList [i]);
//Get the file name witout the extension
var myFileName = documentName.name.substr(0,documentName.name.lastIndexOf("."));
//Get the file extension
var myFileExt = documentName.name.substr(documentName.name.lastIndexOf(".") ,documentName.name.length);
//Write the value of myFileName
$.writeln(myFileName);
//Write the value of myFileExt
$.writeln(myFileExt);
//Rename the file worked on so that it is not picked up again and processed
documentName.rename(myFileName + myFileExt + ".complete");
}
}
}
//Close the folderlist that it is reading
folderList.close();
//The next two lines close Photoshop when it is done processing
var idquit = charIDToTypeID( "quit" );
executeAction( idquit, undefined, DialogModes.ALL );
//This is the function responsile for saving files.
function SavePSD(saveFile)
{
var psdFile = new File(saveFile);
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
psdSaveOptions.layers = true;
psdSaveOptions.annotations = true;
psdSaveOptions.spotColors = true;
document.saveAs (psdFile, psdSaveOptions, true, Extension.LOWERCASE);
//var document2 = app.activeDocument
//document2.saveAs (saveLocation);
}