PS4 scripting

Author
Discussion

paul.deitch

Original Poster:

2,142 posts

263 months

Tuesday 30th March 2021
quotequote all
Yes I'm still using PS4 (paid for) which does a million things more than I'll ever need or understand.

I'm using Vuescan (also paid for) to scan multiple black/white photos from the 30s/40s/50s photos on a flatbed and then using the PS4 crop and straighten function which is wonderful. I find the Vuescan crop and straighten function is not very reliable.
I found a PS4 javascript somewhere on the internet which can fix a folder full of images but produces jpegs when I want tiff.
Knowing nothing about java or PS scripting I tried a few changes but always get a variation of Error 22 / xx Has No Constructor, or Error 22: tiffOptions has no constructor, basically because I haven't got a clue what I'm doing.

Does someone know the correct changes to this java code to provide TIFF format output files?

//Save as a JPEG to the outputFolder
var jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = 11;
jpegOptions.embedColorProfile = false;
app.activeDocument.saveAs( File( outputFolder + "/" + activeDocument.name + ".jpg"), jpegOptions, false);

This is my latest attempt...
//Save as a TIFF to the outputFolder
var tiffOptions = new TIFFSaveOptions();
tiffOptions.embedColorProfile = true;
tiffOptions.imageCompression=TIFFEncoding.NONE;
app.activeDocument.saveAs( File( outputFolder + "/" + activeDocument.name + ".tif"), tiffOptions, false);

I have searched on the internet but so far have not found what I need.

Simpo Two

86,685 posts

271 months

Tuesday 30th March 2021
quotequote all
Does PS4 have 'Actions'? It's not intuitive but I've used it once or twice in the past for batch jobs.

paul.deitch

Original Poster:

2,142 posts

263 months

Wednesday 31st March 2021
quotequote all
Well I worked it out in the end and here is a PS javascript which will do either jpg and/or tif and straighten and separate multiple images and might help some other scanner save a lot of time.

// cropAndStraightenBatch.jsx
// Copyright 2006-2008
// Written by Jeffrey Tranberry
// Photoshop for Geeks Version 2.0

/*
Description:
This script demonstates how to batch process
a folder of images using the crop and straighten command
  • /
// enable double clicking from the
// Macintosh Finder or the Windows Explorer
  1. target photoshop
// Make Photoshop the frontmost application
// in case we double clicked the file
app.bringToFront();

/////////////////////////
// SETUP
/////////////////////////

// A list of file extensions to skip, keep them lower case
gFilesToSkip = Array( "db", "xmp", "thm", "txt", "doc", "md0", "tb0", "adobebridgedb", "adobebridgedbt", "bc", "bct" );

/////////////////////////
// MAIN
/////////////////////////

main();

function main() {
//Make sure there are no open documents
if (app.documents.length > 0){
alert ("This script requires that there are no open documents to run.");
}else{

// Pops open a dialog for the user to choose the folder of documents to process
var inputFolder = Folder.selectDialog("Select a folder of documents to process");

// Pops open a dialog for the user to set the output folder
var outputFolder = Folder.selectDialog("Select a folder for the output files");

// Open and process a folder of Images
OpenFolderRecursively(inputFolder, outputFolder);

}
}

/////////////////////////
// FUNCTIONS
/////////////////////////

// Given the a Folder of files, open the files and process them
function OpenFolderRecursively(inputFolder, outputFolder) {
var filesOpened = 0;
var fileList = inputFolder.getFiles();
for ( var i = 0; i < fileList.length; i++ ) {
// Make sure all the files in the folder are compatible with PS
if ( fileList[i] instanceof File && ! fileList[i].hidden && ! IsFileOneOfThese( fileList[i], gFilesToSkip )) {
open( fileList[i] );
filesOpened++;

/////////////////////////
// Put all your processing functions...
/////////////////////////

// Create a variable to store a reference to
// the currently active document, which in this
// case is the parent document we want to extract
// multiple scanned images from
var docRef = app.activeDocument;

// Run the cropAndStraighten function
// which will rusult in more than one open document
cropAndStraighten();

// Close the parent document we originally opened
docRef.close(SaveOptions.DONOTSAVECHANGES);

// Process all open documents until no documents
// are left open.
while (app.documents.length >=1){

/////////////////////////
// Put all your processing functions...
/////////////////////////

// Flatten the document in case the file type we want to save to requires a flat doc
app.activeDocument.flatten();

//Save as a JPEG to the outputFolder
//var jpegOptions = new JPEGSaveOptions();
//jpegOptions.quality = 11;
//jpegOptions.embedColorProfile = false;
//app.activeDocument.saveAs( File( outputFolder + "/" + activeDocument.name + //".jpg"), jpegOptions, false);

//Save as a TIFF to the outputFolder
var tiffSaveOptions = new TiffSaveOptions();
//tiffOptions.embedColorProfile = true;
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.imageCompression=TIFFEncoding.NONE;
app.activeDocument.saveAs( File( outputFolder + "/" + activeDocument.name + ".tif"), tiffSaveOptions, false);



// Close without saving
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

/////////////////////////
// ...in the area between these two comments.
/////////////////////////
}

/////////////////////////
// ...in the area between these two comments.
/////////////////////////

}

// go recursive
if (!(fileList[i] instanceof File)) {
var newOuputFolder = new Folder(outputFolder + "/" + new Folder(fileList[i]).name);
newOuputFolder.create();
OpenFolderRecursively(fileList[i], newOuputFolder);
}
}
return filesOpened;
}

// given a file name and a list of extensions
// determine if this file is in the list of extensions
function IsFileOneOfThese( inFileName, inArrayOfFileExtensions ) {
var lastDot = inFileName.toString().lastIndexOf( "." );
if ( lastDot == -1 ) {
return false;
}
var strLength = inFileName.toString().length;
var extension = inFileName.toString().substr( lastDot + 1, strLength - lastDot );
extension = extension.toLowerCase();
for (var i = 0; i < inArrayOfFileExtensions.length; i++ ) {
if ( extension == inArrayOfFileExtensions[i] ) {
return true;
}
}
return false;
}

// Crop and Straighten function created
// using the ScriptingListener plug-in
function cropAndStraighten(){
var id333 = stringIDToTypeID( "CropPhotosAuto0001" );
executeAction( id333, undefined, DialogModes.NO );
}