Hello all,
I need a script to load the ‘Save A Copy’ Dialog in Photoshop. I tried " getFileForSaving()" however I am not getting the result I need. I need the to simply load the dialog and let the user to pick the file format and settings already available in photoshop, instead of me writing acode for specific format.
I tried alchemist but the batchPlay descriptor I get doesn’t load the dialog!
really appreciate any help!
create an action then from the action panel select the item
copy as javascript and paste the code where you need it.
thanks. I tried this, however the action converted to javascript is the same batchplay as what alchemist listen function does (which doesn’t work).
can you please share the code, I suspect the cause to be modal behaviour
you can try removing that object and try to run without the execasmodal
Thanks! this is the code I used but I did use the execasmodal.
const {executeAsModal} = require(“photoshop”).core;
const {batchPlay} = require(“photoshop”).action;
async function actionCommands() {
const result = await batchPlay(
[
{
_obj: “get”,
_target: [
{
_property: “fileSavePrefs”
},
{
_ref: “application”,
_enum: “ordinal”,
_value: “targetEnum”
}
],
_options: {
dialogOptions: “dontDisplay”
}
}
],
{}
);
}
async function runModalFunction() {
await executeAsModal(actionCommands, {“commandName”: “Action Commands”});
}
await runModalFunction();
In other words, you just want to invoke Save A Copy? Try performMenuCommand.
const main = async () => {
const { core } = require('photoshop') ;
try {
await core.executeAsModal(
async (context) => {
await core.performMenuCommand( {commandID: 33} ) ;
},
{
'commandName': 'Save A Copy'
}
) ;
} catch(e) {
console.log(e) ;
}
} ;
thank you so much! this works like a charm!
A follow up question, is it possible to get the properties of the file saved after running the main()? (file format, name, location etc)? I need the repeat the Save As copy on each layer with the settings used with Save As Copy dialog, ideally without prompting the user again.
I’d appreciate your help once more!
is it possible to get the properties of the file saved after running the main()? (file format, name, location etc)?
Perhaps that is not possible in the case of performMenuCommand. A different approach is needed, such as creating the Save A Copy behavior and UI from scratch.
The layer-by-layer iteration could be accomplished in the following way, as long as the exported file can be found.
- Duplicate the exported file via the file system
- Open the duplicated file in Photoshop
- Make the necessary edits and save overwrite the file, leaving only the target layer
I had a feeling it wouldn’t be possible. Thank you so much again nevertheless. You’re utmost helpful!