Thanks StefanK,
Awesome as always. There is still an issue getting the javascript to use the variable being passed. I’m not sure if the the javascript is expecting POSIX or HFS either or if it needs a path including the volume as the current script returns /Users/mark/Desktop/Test/ and I’m not that familiar with javascript. It also seems that I will need to modify the javascript a little to get the path into the function that needs it. Below is the javascript.
/*
This script will scan folders and subfolders for tiffs, open and compress them with LZW compression.
It can be modified to open and recompress jpegs or to open tiffs and save jpegs.
/
var Q = 9; //the jpeg quality used if saving as jpeg
var openType = ".tif";//change this to open pdf or jpg if you choose
var saveType = “tif”; //will also save pdf or jpg format
function main(openType,Q,saveType){
var topFolder = myFolder //Folder.selectDialog(“Select the top folder containing your images.”)
var docPath = topFolder;
var whatFolders = new Array();
whatFolders = scanSubFolders(topFolder)
var tFileList;
var fileList;
var whatsK = 1;
if(whatFolders.length == 1){whatsK = 0;}
for(var k = whatsK; k < whatFolders.length; k++){
var docFolder = new Folder(whatFolders[k]);
var files = docFolder.getFiles(openType)
var docRef;
for(i=0;i<files.length;i++){
if(files[i].readonly == true){files[i].readonly = false;}
try{docRef = open(files[i])} catch(e){ }
//var docRef = activeDocument; //the open document, used later to save
var docPath = docRef.fullName.parent.fsName;
saveType = saveType.toLowerCase();
if(saveType == "jpg" || saveType == "jpeg") saveAsJPG(docRef,docPath,Q);
if(saveType == "tif" || saveType == "tiff") saveAsTIFF(docRef,docPath);
if(saveType == "pdf") saveAsPDF(docRef,docPath,Q);
docRef.close(SaveOptions.DONOTSAVECHANGES);
}
}//end first for loop
}
function saveAsTIFF(dRef,dPath){
tifFile = new File(dPath + “/” + dRef.name); //theDocumentName
TifSaveOptions = new TiffSaveOptions();
TifSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
TifSaveOptions.embededColorProfile = true;
TifSaveOptions.layers = false;
dRef.saveAs(tifFile, TifSaveOptions, false, Extension.LOWERCASE); //(name,options,as copy?,ext);
}
function saveAsJPG(dRef,dPath,Q){
jpgFile = new File(dPath + “/” + dRef.name);
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = Q;
dRef.saveAs(jpgFile, jpgSaveOptions, false, Extension.LOWERCASE); //(name,options,as copy?,ext);
}
function saveAsPDF(dRef,dPath,Q){
pdfFile = new File(dPath + "/" + dRef.name);
var pdfSaveOptions = new PDFSaveOptions();
pdfSaveOptions.alphaChannels = false;
pdfSaveOptions.annotations = false;
pdfSaveOptions.downgradeColorProfile = true;
pdfSaveOptions.embedColorProfile = true;
pdfSaveOptions.encoding = PDFEncoding.JPEG;
pdfSaveOptions.interpolation = false;
pdfSaveOptions.jpegQuality = Q;
pdfSaveOptions.layers = false;
pdfSaveOptions.spotColors = false;
pdfSaveOptions.transparency = false;
pdfSaveOptions.useOutlines = false;
pdfSaveOptions.vectorData = false;
dRef.saveAs(pdfFile, pdfSaveOptions, false, Extension.LOWERCASE); //(name,options,as copy?,ext);
}
function scanSubFolders(tFolder)
{
var sFolders = new Array();
var allFiles = new Array();
sFolders[0] = tFolder;
for (var j = 0; j < sFolders.length; j++) // loop through folders
{
var procFiles = sFolders[j].getFiles();
for (var i=0;i<procFiles.length;i++) // loop through this folder contents
{
if (procFiles[i] instanceof Folder){sFolders.push(procFiles[i]);
}
}
}
return sFolders;
}
main(openType,Q,saveType,myFolder);
// end of javascript
The applescript does trigger the script but then I get an error that myFolder is undefined at the line in the javascript that calls the “main” function
main(openType,Q,saveType,myFolder);
I may need to find a javascript forum to find out how to handle the variable being passed.
Thanks for your help,
Mark