How to save active Document as PSD , PDD or PSDT format in UXP Photoshop Plugin?

Suppose I have file name a_b_c.psd which is dynamically generated. it can be either PSD, PSD, or PSDT format. the code below saves only PSD format but I want to save as the format of the newFileName has. the other two formats PDD and PSDT are not saved in this way. what can I do now?

const newFile = await folder.createFile(newFileName);
const document = app.activeDocument;
await document.saveAs.psd(newFile);

You can use batchPlay to access PS features not covered by the API.
https://developer.adobe.com/photoshop/uxp/2022/ps_reference/media/batchplay/

1 Like

thanks for replying. I have used batchPlay already. This is my code. can you please give me specific directions to save the file in the format of the newFileName? it can be either PSD, PDD or PSDT.

	const newFileName = rootScope.generatedFileName + "." + rootScope.fileType.toLowerCase();
	const thePersistentFolder = await rootScope.folderLocation;
	const theNewFile = await thePersistentFolder.createFile(newFileName, { overwrite: true });
	const saveFile = await require("uxp").storage.localFileSystem.createSessionToken(theNewFile);
	const cmd = [{
		"_obj": "save",
		"as": {
			"_obj": "photoshop35Format",
			"maximizeCapability": false
		},
		"in": {
			"_path": saveFile,
			"_kind": "local"
		},
		"documentID": app.activeDocument._id,
		"saveStage": {
			"_enum": "saveStageType",
			"_value": "saveBegin"
		},
		"_isCommand": false
	}]
	await require("photoshop").action.batchPlay(cmd, {});

What youā€™ve got there is the saveBegin descriptor, you want the saveSucceded one (I donā€™t really know the specifics of each, I just know that in Alchemist you want the 2nd save stage it records).
Hereā€™s that descriptor (Itā€™s very similar) - your code is otherwise fine.

{
  _obj: "save",
  as: {
    _obj: "photoshop35Format"
  },
  in: {
    _path: <pass-token-here>,
    _kind: "local"
  },
  documentID: <pass-document-ID-here>,
  lowerCase: true,
  saveStage: {
    _enum: "saveStageType",
    _value: "saveSucceeded"
  },
  _options: {
    dialogOptions: "dontDisplay"
  }
}
2 Likes

Thank you very much. The code that you have provided only saves as psd but pdd and psdt format are not saved though my file name has pdd or psdt ext. Suppose I have the file name as ā€˜demo.pddā€™. I want to save the file as pdd format but it is saved as ā€˜demo.psdā€™. what should I do about this? Thanks in advance.

Hmm, Iā€™m not sure. Iā€™m not familiar with either file type.
Iā€™ll have an experiment and see what I can come up with.

1 Like

I think youā€™re going to have to manually rename the file post-save.

Actually, I am trying not to do it manually.

The only other thing I can think of is

as: {
  _obj: "photoshop35Format"
}

being set to a different value like "largeDocumentFormat" as per PSB files. What those values might be (or if they even exist) I have no idea, nor how one might even go about finding them.

Perhaps @Jarda has some insights on the matter?

1 Like

The last time I askedā€¦ we are supposed to use only PSD or PSB from Photoshop document file formats. Not cloud document file extension or template or others. But that was a few months back. Why do you want to use it?

1 Like

How to ā€œmakeā€ a template .psd file? Add a ā€œtā€ to the end using the file system (not saveAs). Yes, it is literally just the file extension: psdt.

1 Like