Skip to main content
jkmgz
Inspiring
January 30, 2020
Answered

Photoshop Constant Code for PSD default format??

  • January 30, 2020
  • 4 replies
  • 859 views

I have a working script using .saveAs to save my current file as a PSD to a location on my computer. Although, it doesn't set the current working document to that newly saved PSD. The goal is to set the current document to the saved PSD and (from my research) the only way to do that is with action descriptors. I have the working code for saving TIFF file using action descriptors below: 

 

function saveTIFF() {
var c2t = function (s) {
return app.charIDToTypeID(s);
};
 
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
 
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
 
descriptor2.putEnumerated( s2t( "byteOrder" ), s2t( "platform" ), s2t( "macintosh" ));
descriptor.putObject( s2t( "as" ), c2t( "TIFF" ), descriptor2 );
descriptor.putPath( c2t( "In " ), new File("/Users/geary/Desktop/newtifffile.tif") );
descriptor.putInteger( s2t( "documentID" ), 813 );
descriptor.putBoolean( s2t( "lowerCase" ), true );
descriptor.putEnumerated( s2t( "saveStage" ), s2t( "saveStageType" ), s2t( "saveSucceeded" ));
executeAction( s2t( "save" ), descriptor, DialogModes.NO );
}
 
For me, the culprit code that changes this from a TIFF save to a PSD save and making the active document the saved PSD, is the .putObject's 2nd argument showing c2t( "TIFF" ). I could be wrong there! Although, if I am correct, the next issue is the code to use for the "default" PSD Format. Per this document, is a list of Photoshop Constants. I picked out the ones specific to the phClassPhotoshop prefix, shown below:

phClassPhotoshopDCSFormat -> 1349010481 -> "PhD1" photoshopDCSFormat
phClassPhotoshopDCS2Format -> 1349010482 -> "PhD2" photoshopDCS2Format
phClassPhotoshop20Format -> 1349022770 -> "Pht2" photoshop20Format
phClassPhotoshop35Format -> 1349022771 -> "Pht3" photoshop35Format
phClassPhotoshopEPSFormat -> 1349022789 -> "PhtE" photoshopEPSFormat
phClassPhotoshopPDFFormat -> 1349022800 -> "PhtP" photoshopPDFFormat
 
I am unsure which one to proceed with if my presumtions are correct about the code. I was planning on choosing one and testing it out, but that still doesn't give validity of which code is the default PSD format. 
 
I would immensley appreciate any help in figuring this out. Thank you, in advance, for your time and efforts. 
This topic has been closed for replies.
Correct answer Stephen Marsh

Bump... Only a few members here post hand-coded AD code. Many post AM code recorded by the SL plugin, either raw or through the Clean SL script, with or without modifications swapping out recorded values for variables.

 

Looking at saving a Photoshop file and then only changing the "as a copy" option then comparing the code differences, I can at least confirm the following:

 

(1) Yes, charIDToTypeID( "Pht3" ) does indeed appear to be the correct format for standard/modern PSD.

 

(2) The extra bit of code that the "as a copy" checkbox adds is charIDToTypeID( "Cpy " )

 

4 replies

Stephen Marsh
Community Expert
Community Expert
January 31, 2020

The acronyms were:

AM = Action Manager code, recorded using the Scripting Listener plugin.

AD = Action Descriptor code, which from my understanding is generally hand coded

 

Yes, AD code is obviously used within AM code and one can of course copy from AM to AD. I was making a distinction between the two related methods of coding, which are not as friendly to read as standard Document Object Model (DOM) code. But I'm just a beginner and may be misusing these terms.

Stephen Marsh
Community Expert
Community Expert
January 31, 2020

Perhaps I'm missing something as it is late... Does the following do what you need (obviously change the path/name)?

 

Raw AM code from SL:

 

 

var idsave = charIDToTypeID( "save" );
    var desc983 = new ActionDescriptor();
    var idAs = charIDToTypeID( "As  " );
        var desc984 = new ActionDescriptor();
        var idmaximizeCompatibility = stringIDToTypeID( "maximizeCompatibility" );
        desc984.putBoolean( idmaximizeCompatibility, true );
    var idPhtthree = charIDToTypeID( "Pht3" );
    desc983.putObject( idAs, idPhtthree, desc984 );
    var idIn = charIDToTypeID( "In  " );
    desc983.putPath( idIn, new File( "~/Desktop/test.psd" ) );
    var idDocI = charIDToTypeID( "DocI" );
    desc983.putInteger( idDocI, 1099 );
    var idLwCs = charIDToTypeID( "LwCs" );
    desc983.putBoolean( idLwCs, true );
    var idsaveStage = stringIDToTypeID( "saveStage" );
    var idsaveStageType = stringIDToTypeID( "saveStageType" );
    var idsaveBegin = stringIDToTypeID( "saveBegin" );
    desc983.putEnumerated( idsaveStage, idsaveStageType, idsaveBegin );
executeAction( idsave, desc983, DialogModes.NO );

 

 

The same code through Clean SL:

 

 

save(true, new File( "~/Desktop/test.psd" ), true);
function save(maximizeCompatibility, In, lowerCase) {
	var c2t = function (s) {
		return app.charIDToTypeID(s);
	};

	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};

	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();

	descriptor2.putBoolean( s2t( "maximizeCompatibility" ), maximizeCompatibility );
	descriptor.putObject( s2t( "as" ), s2t( "photoshop35Format" ), descriptor2 );
	descriptor.putPath( c2t( "In  " ), In );
	descriptor.putInteger( s2t( "documentID" ), 1099 );
	descriptor.putBoolean( s2t( "lowerCase" ), lowerCase );
	descriptor.putEnumerated( s2t( "saveStage" ), s2t( "saveStageType" ), s2t( "saveBegin" ));
	executeAction( s2t( "save" ), descriptor, DialogModes.NO );
}

 

 

With save as a copy adding the following option to the raw code above:

 

 

var idCpy = charIDToTypeID( "Cpy " );
desc1007.putBoolean( idCpy, true );

 

 

or the cleaned code additions:

 

 

function save(maximizeCompatibility, In, copy, lowerCase) {

//...

descriptor.putBoolean( s2t( "copy" ), copy );

 

jkmgz
jkmgzAuthor
Inspiring
January 31, 2020

I'm not sure I'm following you on the acronyms you're using, but I have the working function below: 

function savePSDtoActive(filepath) {  

    savingPathWithFile = removeExt(filepath) + ".psd";

    var c2t = function (s) {  
    return app.charIDToTypeID(s);  
    };  
    
    var s2t = function (s) {  
    return app.stringIDToTypeID(s);  
    };  
    
    var descriptor = new ActionDescriptor();  
    var descriptor2 = new ActionDescriptor();  
    
    descriptor2.putEnumerated( s2t( "byteOrder" ), s2t( "platform" ), s2t( "macintosh" ));  
    descriptor.putObject( s2t( "as" ), c2t( "Pht3" ), descriptor2 );
    descriptor.putPath( c2t( "In  " ), new File(savingPathWithFile) );  
    descriptor.putInteger( s2t( "documentID" ), 813 );  
    descriptor.putBoolean( s2t( "lowerCase" ), true );  
    descriptor.putEnumerated( s2t( "saveStage" ), s2t( "saveStageType" ), s2t( "saveSucceeded" ));  
    executeAction( s2t( "save" ), descriptor, DialogModes.NO );  
  
  }

//accompanied with:
function removeExt(path) {
    var pathX = path.split("/"),
        pathXL = pathX.length - 1,
        lastPathItem = pathX[pathXL];
    var filenameX = lastPathItem.split(".");
    filenameX.pop();
    var nameOnly = filenameX.join(".");
    pathX.pop();
    var returningPath = pathX.join("/") + "/" + nameOnly;
    return returningPath;
}
Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
January 31, 2020

Bump... Only a few members here post hand-coded AD code. Many post AM code recorded by the SL plugin, either raw or through the Clean SL script, with or without modifications swapping out recorded values for variables.

 

Looking at saving a Photoshop file and then only changing the "as a copy" option then comparing the code differences, I can at least confirm the following:

 

(1) Yes, charIDToTypeID( "Pht3" ) does indeed appear to be the correct format for standard/modern PSD.

 

(2) The extra bit of code that the "as a copy" checkbox adds is charIDToTypeID( "Cpy " )

 

jkmgz
jkmgzAuthor
Inspiring
January 30, 2020

I am still unsure what the proper constant should be used for the default PSD, but I wanted to confirm that this does work with app.charIDToTypeID("Pht3") but does not work with app.charIDToTypeID("Pht2"). A handy find I was able to reveal whilst poking at the process/code.