Saving a new Photoshop document (advanced)

Hi!

The TL;DR is I’d like to be able to save a new, dynamically generated Photoshop document on the user’s local disk in a specific location using either BatchPlay or the Storage API, WITHOUT prompting the user to save the document.

(I’ll already have permissions to the folder in question via a persistent token, so there’s no shenanigans going on here.).

I’ve tried a few things, but can’t quite get there. Any ideas?

More details:

  • The general idea is that a PSD/PSB will be dynamically created for the user based external inputs, then saved to their local disk while they do work. Later, that saved file will be synced to the cloud for the user’s later access and storage.
  • Again, I’ll already have a persistent token for the parent folder, (or I will ask for permission to access the parent folder before the attempted save, if not) so I should theoretically be able to save this without additional user interaction.
  • folder.createFile doesn’t seem to have a method for taking the current active document (or any open document) and making a file that’s appropriate for saving. (Perhaps I need to get the binary data of the PSD/PSB and use this API accordingly?)
  • BatchPlay complains when I try to save manually, because (of course) it needs a file access token. Is it possible to provide an existing token for the parent folder to accomplish this?
  • Here’s the specific BatchPlay command I was using: (saveFile is a string, indicating where on the local drive I want to save the file)
    image

Happy to provide more code examples or clarify anything that’s confusing!

What type is saveFile? Might be useful to see where you’re getting that value.

Ah, saveFile is the string value of the path where I want to save the file.

Yeah, so saveFile will need to be either a session token or a persistent token, not the physical path. Until you get that, batchPlay is going to complain.

createFile won’t actually put a file on disk until you write something to it. As such, you can just call createFile, and then generate the persistent token from that file. Then pass it to batchPlay.

I think something like this should work for you:

const thePersistentFolderToken = localStorage.getItem("persistentFolder");
const thePersistentFolder = await fs.getEntryForPersistentToken(thePersistentFolderToken);
const theNewFile = await thePersistentFolder.createFile("export.psd", {overwrite: true});
const saveFile = await fs.createSessionToken(theNewFile);

Then pass saveFile to batchPlay.

1 Like

AHH. Thank you!

So to confirm, the workflow is:

  1. Get the folder Entry using the persistent token.
  2. Create a new File inside the folder Entry.
  3. Get the resulting File Entry (which will need its own token).
  4. Then my "in": { "_path:" ... } value becomes the new File Entry.
  5. Run Batch Play on my open document, and it’ll save.

Am I following correctly?

Yup! That should do the trick!

1 Like

You rock. Thanks a ton!

Are there file options, like jpg quality, convert to profile, and embed profile, that can be added in this method for saving files?

if i want to save the current document as PDD or PSDT format then what should i do?