Last active
July 5, 2020 18:00
-
-
Save kingster/aae0d32fbaec68d217189dc7e4e78bd5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
<javascriptresource> | |
<name>Batch Divide Scans save as TIFF...</name> | |
<about>divide scans and save as TIFF</about> | |
<category>Layers</category> | |
<menu>automate</menu> | |
</javascriptresource> | |
*/ | |
#target Photoshop | |
app.bringToFront; | |
var inFolder = Folder.selectDialog("Please select folder to process"); | |
if (inFolder != null) { | |
var fileList = inFolder.getFiles(/\.(jpg|jpeg|tif|tiff|psd|png|bmp)$/i); | |
var outfolder = new Folder(decodeURI(inFolder) + "/Edited"); | |
if (outfolder.exists == false) outfolder.create(); | |
for (var a = 0; a < fileList.length; a++) { | |
var fName = fileList[a]; | |
var docname = fName.name.slice(0, -4); | |
if (fName instanceof File && !fName.hidden && docname.substr(0,1) !== "#") { | |
var doc = open(fName); | |
doc.flatten(); | |
CropStraighten(); | |
doc.close(SaveOptions.DONOTSAVECHANGES); | |
var count = 1; | |
while (app.documents.length) { | |
var saveFile = new File(decodeURI(outfolder) + "/" + docname + "#" + zeroPad(count, 3) + ".tif"); | |
SaveTIF(saveFile); | |
activeDocument.close(SaveOptions.DONOTSAVECHANGES); | |
count++; | |
} | |
} | |
} | |
alert("Script Completed") | |
}; | |
function CropStraighten() { | |
executeAction(stringIDToTypeID('CropPhotosAuto0001'), undefined, DialogModes.NO); | |
}; | |
function SaveTIF(saveFile) { | |
tifSaveOptions = new TiffSaveOptions(); | |
tifSaveOptions.embedColorProfile = true; | |
tifSaveOptions.alphaChannels = true; | |
tifSaveOptions.byteOrder = ByteOrder.IBM; | |
tifSaveOptions.imageCompression = TIFFEncoding.TIFFLZW; | |
tifSaveOptions.layers = false; | |
activeDocument.saveAs(saveFile, tifSaveOptions, true, Extension.LOWERCASE); | |
} | |
function SavePSD(saveFile) { | |
psdSaveOptions = new PhotoshopSaveOptions(); | |
psdSaveOptions.embedColorProfile = true; | |
psdSaveOptions.alphaChannels = true; | |
psdSaveOptions.layers = true; | |
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE); | |
}; | |
function SaveJPG(saveFile) { | |
var jpegOptions = new JPEGSaveOptions(); | |
jpegOptions.quality = 60; | |
jpegOptions.embedColorProfile = false; | |
activeDocument.saveAs(saveFile, jpegOptions, false); | |
}; | |
function zeroPad(n, s) { | |
n = n.toString(); | |
while (n.length < s) n = '0' + n; | |
return n; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment