I have tried the official sample and just about every variation I can find in the forums and I cannot seem to save a file to any directory including the plugin temp or the plug in data.
I’ve tried adding synchronousExecution: true to the batchPlay just to see what happens but makes no difference. I dont get any error returned in the response from batchPlay either. Maybe its busted?
I think you’re supposed to pass a file token, not a path in batchPlay commands. It’s a bit misleading since the parameters are still called ‘folder’ or ‘path’, but in my experience it requires a file token. I wrote about this in a recent post.
In a nutshell you can obtain a token by calling createSessionToken and providing your folder entry, as described here.
It still doesn’t export an image to the temp directory. I’ve tried passing different things to the destFolder like “temp.url” and “temp.nativePath”. I never get any error thrown or any error returned from the batch play results. Im running on Windows 10 and PS 25.4. Im not sure what else to try. Btw, are there any official docs on each of the batchplay commands? Thanks!
And just to double check, you do have a layer with id=4 (which is your current target in the descriptor)? I’m not familiar with this particular batchPlay command. I typically use Alchemist to get a descriptor and then modify the target to make sense.
Ok, but those are different things. The thing that you just posted grabs the active layer (do you have one selected?). The original code grabs one particular layer (assuming one exists with id=4, which isn’t an index btw.).
@Jarda is your man for Alchemist He would probably know. The way I typically use it is by recording what I do in Photoshop and then looking at the generated descriptor code and then wrap it in a function adjusting targets to make sense.
Btw. are you trying to export the whole document or a particular layer? If you’re trying the former then I would definitely recommend using the API (check out these docs). It would literally be one line of code. (For the latter you could probably also use the API, with a few more lines of code).
Ok, but those are different things. The thing that you just posted grabs the active layer (do you have one selected?). The original code grabs one particular layer (assuming one exists with id=4, which isn’t an index btw.).
Oh yes I know, I do have a layerID that is 4 (I verified that by running a select command in Alchemist with layerID 4)
I have tried the imaging API but it seems like it outputs a jpg? Is there a way to get png from it?
The document.saveAs method is interesting. Does that open a user dialog by default?
So it would basically be something like this (assuming you have a reference to your document):
let entry = await require('uxp').storage.localFileSystem.getFileForSaving("target.png");
document.saveAs.png(entry);
You can pass options (you can look at the docs for details). This won’t open a user dialog. Only getting the file for saving will bring up a dialog to provide the output location.
That particular function will always bring up a dialog. However, there are locations (e.g. temp folders or the plugin folder, for which you don’t need access permissions and you can create a temp file in there). You can also access a random location on disk by providing a file path. If you search for any of those key words in the forum you will find a plethora of threads (there’s practically at least one person per week asking this ). E.g check out this post, from myself a while ago.
I would also recommend looking through the docs for file access and read it in full to understand what you can do with and without permissions from the user.
This still will spawn a dialog even with the domains.appLocalTemporary and I suppose that is expected.
Looking at the file access for manifest it looks like all I need is "localFileSystem": "plugin" in the permissions section but that is the default value anyways.
As far as the original question of does the command “exportSelectionAsFileTypePressed” work anymore, it seems to me like that is no (I would love to be wrong about that). So now I’m looking into some other options to save a png to the temp plugin directory. Thanks for your help!
I don’t quite understand why you still use getFileForSaving. Again, that will bring up a dialog always. That is the way to ask a user to specify a file (and give permission to access it).
In your case you’re already getting a temp folder, via getTemporaryFolder. You have trivial access to that folder (so no pop-up will occur). Now it’s just a case of creating a file in that folder via createFile (as described here) and pass that to saveAs.
P.S. There’s an almost identical thread in this forum from just a week ago. The person there wanted to save a .jpg. It sounds like you want to save a .png. Check it out.
Thanks! I think I’ve come full circle now lol. This is what I started with before I made this post. For some reason I thought it would only output a jpg.