• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Script to convertProfile brings up dialog box even though I have supplied necessary parameters.

Community Beginner ,
Jul 23, 2020 Jul 23, 2020

Copy link to clipboard

Copied

Greetings,

 

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).

 

The line (48) that causes the dialog box to appear is as follows:

 

document.convertProfile("SWOP2013C3_CRPC5.icc" , Intent.RELATIVECOLORIMETRIC);

 

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);
}
TOPICS
Actions and scripting

Views

547

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Jul 23, 2020 Jul 23, 2020

Copy link to clipboard

Copied

The variable document has been declared on line 28.

 

It has also been re-defined on line 100?

 

You could also try changing the offending line from:

 

document.convertProfile("SWOP2013C3_CRPC5.icc" , Intent.RELATIVECOLORIMETRIC);

 

to

 

app.activeDocument.convertProfile("SWOP2013C3_CRPC5.icc" , Intent.RELATIVECOLORIMETRIC);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 24, 2020 Jul 24, 2020

Copy link to clipboard

Copied

GIF, PNG, and BMP formats do not support CMYK. So any of those will throw an error of some type.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jul 24, 2020 Jul 24, 2020

Copy link to clipboard

Copied

Dialog window will pop up if the profile name is incorrect and app.displayDialogs = DialogModes.ERROR is set.
Replace the code
document.convertProfile("SWOP2013C3_CRPC5.icc" , Intent.RELATIVECOLORIMETRIC);

with

try {
    app.displayDialogs = DialogModes.NO;
    document.convertProfile("SWOP2013C3_CRPC5.icc" , Intent.RELATIVECOLORIMETRIC);
    }
catch (e) { alert(e); throw(e); }

 

Not sure if the name "SWOP2013C3_CRPC5.icc" is correct. You need to use what you see in the drop-down list of the dialog and most likely without the ".icc" at the end.
 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 24, 2020 Jul 24, 2020

Copy link to clipboard

Copied

LATEST

Some profiling programs add a file extension to the internal profile name. If this profile is not synthetic, but built by measurements, then it can be with the extension in the profiles list.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines