Skip to main content
Gibson Editions
Inspiring
May 12, 2025
Answered

Photoshop output script inconsistent

  • May 12, 2025
  • 1 reply
  • 349 views

I created the following script to output files to a hotfolder for a printer rip. It has worked seamlessly for years, but now it has become developed a bug. 

 

The purpose of the script is to flatten, convert, crop and save the files into a folder. 

 

It always saves crops and converts the file, however sometimes i am not sure why it seems to turn off a number of layers or groups. The problem is that when i go to reproduce the error the bug doesnt appear. So i go back to using the script again and it happens again. Maybe im missing something very obvious or some part of the code is now obselete in photoshop. Any help would be much appreciated 

 

I am on Photoshop 26.6.1

 

MAIN SCRIPT 

#include outputFunctions.jsx
#target photoshop
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.displayDialogs = DialogModes.NO;

var dir = PRINTING;
printOUT()
var fileEnding = "_proof";
var ICCprofile = "ISO Coated v2 (ECI)";
var layoutVIS = true;
layVisble ()
cropORnot()
var alphaChan = false;
var layerVis = false;
////// function //////
//var myFolder = Folder(dir).selectDlg("Select a Folder to save files in")

var myFolder = dir
for (var i = documents.length - 1; i >= 0; i--) {
    

//for (var i = 0; i < fileList.length; i++) {
    
//app.activeDocument = fileList[i]    


cropConvert();


    }


app.preferences.rulerUnits = originalRulerUnits;

function cropConvert(){


var doc = app.activeDocument;  

if (dir == "inFolder") {myFolder = activeDocument.path;}
else {}


saveOptions(doc, myFolder, fileEnding, alphaChan, layerVis);

layoutVis(doc,layoutVIS);


doc.flatten(); 

////// function //////

doc.bitsPerChannel = BitsPerChannelType.EIGHT;


doc.convertProfile( ICCprofile, Intent.RELATIVECOLORIMETRIC, true, true );  
//crop with guides
if (crop== true){
cropWguides(doc);}
else{}

//save functions
doc.saveAs(tiffFile, tiffSaveOptions, false, Extension.LOWERCASE);
doc.close(SaveOptions.DONOTSAVECHANGES)

}



    

 

 

OUTPUT FUNCTIONS

//JMP functions
// to use in script put #include outputFunctions.jsx at top of script

PRINTING = "~/03_PRINTING//"
SENDING = "~/04_SENDING//"
VERIFY = "~/05_VERIFY//"
VIDEO = "~/09_VIDEO//"
INSTA = "~/09_INSTA//"
LOCAL_PRINT = "~/08_LOCALPRINT//"
EMAIL = "~/07_EMAIL//"


//LG functions

//Printers

PRINTER1 = "EpsonStylusPro4900-26C624 (IP)"
PRINTER2 = "EpsonStylusPro4900-26DD8B (IP)"
PRINTER3 = "EpsonStylusPro7900-162921 (IP)"

function printerType(){

  var w = new Window ("dialog");
  w.alignChildren = "left";
  var radio1 = w.add ("radiobutton", undefined, PRINTER1);
  var radio2 = w.add ("radiobutton", undefined, PRINTER2);
  var radio3 = w.add ("radiobutton", undefined, PRINTER3);
  
  var yes = w.add('button', undefined, "OK");   
  radio1.value = true; w.show ();
  yes.onClick = function() { 
    w.close()  
    }
  
   if (radio1.value == true) {  printType = PRINTER1}
   if (radio2.value == true) {  printType = PRINTER2}
   if (radio3.value == true) {  printType = PRINTER3}

    

   
   }
  



// PORTFOLIO PAGE DIMENSIONS
fWidth = 356;
fHeight = 279;
fBorder = 50;
Res = 300;


function LSedge(){

var w = new Window ("dialog");

w.alignChildren = "left";
 btnPnl = w.add('panel', undefined, "Resize using?");
var radio1 = w.add ("radiobutton", undefined, "Long Edge");
var radio2 = w.add ("radiobutton", undefined, "Short Edge");
var yes = w.add('button', undefined, "OK");   
radio1.value = true; w.show ();
yes.onClick = function() { 
  w.close()  
  }

 if (radio1.value == true) {lEdge = true ;
     
    dialogDesc = "What would you like your long edge of the image to be?"  }

 if (radio2.value == true){ lEdge = false;
     dialogDesc = "What would you like your long edge of the image to be?"}

 
 
 }


function jpgOUT(){

var w = new Window ("dialog");
w.alignChildren = "left";
var radio1 = w.add ("radiobutton", undefined, "SENDING");
var radio2 = w.add ("radiobutton", undefined, "EMAIL");
var radio3 = w.add ("radiobutton", undefined, "IN FOLDER");
var yes = w.add('button', undefined, "OK");   
radio1.value = true; w.show ();
yes.onClick = function() { 
  w.close()  
  }

 if (radio1.value == true) {  dir = SENDING}

 if (radio2.value == true){ dir = EMAIL}
  if (radio3.value == true){ dir = "inFolder"}
 
 
 }



function printOUT(){

var w = new Window ("dialog");
w.alignChildren = "left";
var radio1 = w.add ("radiobutton", undefined, "PRINTING");
var radio2 = w.add ("radiobutton", undefined, "LOCAL");
var radio3 = w.add ("radiobutton", undefined, "VERIFY");
var radio4 = w.add ("radiobutton", undefined, "IN FOLDER");

var yes = w.add('button', undefined, "OK");   
radio1.value = true; w.show ();
yes.onClick = function() { 
  w.close()  
  }

 if (radio1.value == true) {  dir = PRINTING}

 if (radio2.value == true){ dir = LOCAL_PRINT}
 
  if (radio3.value == true){ dir = VERIFY}
  
    if (radio4.value == true){ dir = "inFolder"}
 
 }





function ouputOptions(){
var w = new Window ("dialog");
w.alignChildren = "left";
var check1 = w.add ("checkbox", undefined, "Alpha Channels");
var check2 = w.add ("checkbox", undefined, "Layers"); 
var yes = w.add('button', undefined, "OK");     
check1.value = false;
check2.value = false;

yes.onClick = function() { 
  w.close()  
  }


w.show ();

 if (check1.value == true) {  alphaChan = true;}
 else alphaChan = false
 if (check2.value == true){ layerVis = true;}
 else layerVis = false
}



function YNdialog(doc, title, question){


 var dlg = new Window('dialog', title);
        btnPnl = dlg.add('panel', undefined, question);
       YES = btnPnl.add('button', undefined, "Yes");       
       NO = btnPnl.add('button', undefined, "No");       
  
        
 YES.onClick = function() {
       variable = true;
    dlg.close();
    }    

NO.onClick = function (){ 
   variable = false;
       dlg.close();
}    


      dlg.show();
            
  
}



function getDim(doc){
    
    
    
    var Cdim = doc.info.instructions;



var names = Cdim
var nameArr = names.split(',');

     if (nameArr[0] < nameArr[1]){
 
  sDim = nameArr[0]
  lDim = nameArr[1]
  
}
else {
 sDim = nameArr[1]
 lDim = nameArr[0]
}
sDimPx= Math.round((sDim/25.4)*400)
lDimPx= Math.round((lDim/25.4)*400)
}


function c1PathtoGuides(doc){

try{
if (doc.pathItems.getByName('Crop (Capture One)')){

doc.pathItems.getByName('Crop (Capture One)').makeSelection()};
}

catch(e){
doc.selection.selectAll();
}
app.preferences.rulerUnits = Units.PIXELS; // Set the ruler units to PIXELS  
  doc.guides.removeAll(); // clear guides
var Sel = doc.selection.bounds; 

doc.guides.add(Direction.VERTICAL, Sel[0]);  
doc.guides.add(Direction.HORIZONTAL, Sel[1]);  
doc.guides.add(Direction.VERTICAL, Sel[2]);  
doc.guides.add(Direction.HORIZONTAL, Sel[3]); 
doc.selection.deselect();

  

}

function renderIntent(){

  var doc = ""
  var title = "RenderingIntent"
  var question = "Would you like Perceptual?"
  
  YNdialog (doc, title, question)
    if (variable == true) {Rintent = Intent.PERCEPTUAL;}
  else Rintent = Intent.RELATIVECOLORIMETRIC
  
  }




function cropWguides(doc){





if (doc.guides.length == 4) {
// get guides;
var theVert = new Array;
var theHor = new Array;
for (var m = 0; m < doc.guides.length; m++) {
   if (doc.guides[m].direction == Direction.HORIZONTAL) {theVert.push(doc.guides[m].coordinate)}
   else theHor.push(doc.guides[m].coordinate)
       };
   

   // make selection; 
doc.selection.select([[theHor[0], theVert[0]], [theHor[1], theVert[0]], [theHor[1], theVert[1]], [theHor[0], theVert[1]]]);
   };

   
else{
try{
if (doc.pathItems.getByName('Crop (Capture One)')){

doc.pathItems.getByName('Crop (Capture One)').makeSelection()};
}

catch(e){
doc.selection.selectAll();
}
};

   
   






var selBounds = doc.selection.bounds;
doc.crop(doc.selection.bounds);
}

function layoutName(doc){
      if(doc.layers[0].kind == LayerKind.NORMAL){
doc.layers[0].name= "layout";
doc.layers[0].positionLocked = true;          
          }
            else{}
            }


function layVisble(){

var doc = ""
var title = "Layout Visible"
var question = "Would you like the layout on?"

YNdialog (doc, title, question)
  if (variable == true) {layoutVIS = true;}
else layoutVIS = false

}


function cropORnot(){

var doc = ""
var title = "Cropped"
var question = "Would you like the image cropped?"

YNdialog (doc, title, question)
  if (variable == true) {crop = true;}
else crop = false

}

function correctToggleVis(doc){
    
    

  for (var i=0;i<doc.layers.length;i++){
        if(doc.layers[i].name == 'layout'){
              if(doc.layers[i].visible){doc.layers[i].visible = false}
              else{doc.layers[i].visible = true}
              }
        }
    
    }
  


function layoutToggleVis(doc){
    
    

for (var i=0;i<doc.layers.length;i++){
      if(doc.layers[i].kind == LayerKind.NORMAL)
      if(doc.layers[i].name == 'layout'){
            if(doc.layers[i].visible){doc.layers[i].visible = false}
            else{doc.layers[i].visible = true}
            }
      }
  
  }


function layoutVis(doc, VIS ){
    
    
    for (var i=0;i<doc.layers.length;i++){
      if(doc.layers[i].kind == LayerKind.NORMAL)
      if(doc.layers[i].name == 'layout'){
          {doc.layers[i].visible = VIS}
           
            }
      }
    
    }


    


function ShortorLong(doc){
    
    if (lEdge == true){
//resizefunction 
  if (doc.height > doc.width)
{
    //PORTRAIT
Portrait (doc, fHeight)}
else {
    //LANDSCAPE
    Lndscpe(doc, fWidth)}    
        }
    
    else {
        //resizefunction 
  if (doc.height > doc.width)
{
    //PORTRAIT
PortraitS (doc, fHeight)}
else {
    //LANDSCAPE
    LndscpeS(doc, fWidth)}
 }
}


  function Portrait(doc, fHeight){
      doc.resizeImage
      var RsizeI = doc.resizeImage(null,UnitValue(fHeight),UnitValue (Res, "PIXELS"),ResampleMethod.BICUBICAUTOMATIC);
            
}

    function Lndscpe(doc, fWidth) {
    var RsizeI = doc.resizeImage(UnitValue(fWidth),null,UnitValue (Res, "PIXELS"),ResampleMethod.BICUBICAUTOMATIC);
 
    }

  function PortraitS(doc, fHeight){
      doc.resizeImage
      var RsizeI = doc.resizeImage(UnitValue(fHeight),null,UnitValue (Res, "PIXELS"),ResampleMethod.BICUBICAUTOMATIC);
            
}

    function LndscpeS(doc, fWidth) {
    var RsizeI = doc.resizeImage(null,UnitValue(fWidth),UnitValue (Res, "PIXELS"),ResampleMethod.BICUBICAUTOMATIC);
 
    }




function unitSelector(){
// selecting different units made to be combined with unitSwitch function
var w = new Window ('dialog');
var drop = w.add ('dropdownlist', undefined, ["PIXELS", "MM", "INCHES", "CM", "PERCENT"]);
var yes = w.add('button', undefined, "OK");       
drop.selection = 0;
drop.title = 'Units';
drop.titleLayout = {alignment: ['right', 'center']};
//drop.onChange = function() { 
  //  KIND = drop.selection.text;
   
  //w.close()  
    //}
yes.onClick = function() { 
    KIND = drop.selection.text
 
  w.close()  
  }
w.show();



}

// switches units to inches then pixel result requires size, Res and kind
function unitSwitch(){
size = fWidth
unitMultiplier = 0
switch (KIND) {
case "PIXELS":
pX = size
break;     
case "MM":
unitMultiplier = 25.4 ;
var iN = (size/unitMultiplier ) 
pX = (Math.round(iN * Res))
break;
case "INCHES":
unitMultiplier = 1 ;
var iN = (size/unitMultiplier ) 
pX = (Math.round(iN * Res))
break;
case "CM":
unitMultiplier = 2.54 ;
var iN = (size/unitMultiplier )
pX = (Math.round(iN * Res))
break;
}


}



function saveOptions(doc, myFolder, fileEnding, alphaChan, layerVis){

// get the documents name

var myFileName = doc.name;

// remove it's extension
var myDocName = myFileName.substring(0,myFileName.length -4);
if(myDocName.substr(-4,4)== "_RGB"){var myDocName = myDocName.substring(0,myDocName.length -4)}
if(myDocName.substr(-5,5)== "_CMYK"){var myDocName = myDocName.substring(0,myDocName.length -5)}



// set the new filename and path
var myFilePathTiff = myFolder + "/" + myDocName + fileEnding + ".tif";
var myFilePathJpeg = myFolder + "/" + myDocName + fileEnding + ".jpg";
var myFilePathJpeg1 = myFolder + "/" + myDocName + fileEnding + "_2"+ ".jpg";

// tiff file options
 tiffFile = new File(myFilePathTiff);
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.byteOrder = ByteOrder.MACOS;
tiffSaveOptions.layers = layerVis;
tiffSaveOptions.transparency = true;
tiffSaveOptions.alphaChannels = alphaChan;
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.imageCompression = TIFFEncoding.NONE;
tiffSaveOptions.saveImagePyramid = false; 

// jpeg file options
     jpegFile = new File(myFilePathJpeg);
     jpegFile1 = new File(myFilePathJpeg1);
jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = 10;
jpegOptions.FormatOptions = FormatOptions.STANDARDBASELINE;
jpegOptions.embedColorProfile = true;

}

 

 

 

Correct answer creative explorer

@Gibson Editions honstly, I would roll-back to a version that was able to use the written script that worked for so many years past

1 reply

creative explorer
Community Expert
creative explorerCommunity ExpertCorrect answer
Community Expert
May 20, 2025

@Gibson Editions honstly, I would roll-back to a version that was able to use the written script that worked for so many years past

m
Gibson Editions
Inspiring
May 22, 2025

Yeh you're probably right, its probably the best solution.