Copy link to clipboard
Copied
Hi all,
Here's the UXP code taken from the Photoshop Action (enabling debug mode allows you to extract it from a recorded action), it's simply adding a drop shadow to the currently selected layer:
async function action() {
let result;
let psAction = require(\"photoshop\").action;
let command = [
// Set Layer Styles of current layer
{'_obj':'set','_target':[{'_property':'layerEffects','_ref':'property'},{'_enum':'ordinal','_ref':'layer','_value':'targetEnum'}],'to':{'_obj':'layerEffects','dropShadow':{'_obj':'dropShadow','antiAlias':false,'blur':{'_unit':'pixelsUnit','_value':35.0},'chokeMatte':{'_unit':'pixelsUnit','_value':0.0},'color':{'_obj':'RGBColor','blue':0.0,'grain':0.0,'red':0.0},'distance':{'_unit':'pixelsUnit','_value':0.0},'enabled':true,'layerConceals':true,'localLightingAngle':{'_unit':'angleUnit','_value':90.0},'mode':{'_enum':'blendMode','_value':'multiply'},'noise':{'_unit':'percentUnit','_value':0.0},'opacity':{'_unit':'percentUnit','_value':100.0},'present':true,'showInDialog':true,'transferSpec':{'_obj':'shapeCurveType','name':'Linear'},'useGlobalAngle':true},'scale':{'_unit':'percentUnit','_value':100.0}}}
];
result = await psAction.batchPlay(command, {});
}
async function runModalFunction() {
await require('photoshop').core.executeAsModal(action, {'commandName': 'Action Commands'});
}
await runModalFunction();
As I haven't jumped into the world of UXP coding yet, I'm not sure how to extract the correct information above and place into an Applescript. I was hoping the above could be wrapped into a Javascript, which in turn could be called from an Applescript.
The aim is to then apply the same rules to other actions when the focus is on the current layer,
Thanks in advance!
So, after taking your advice I downloaded xbytor2's xtools and it seemed to do the job!
• Download the xtools zip from the xtools website
• Extract and locate the 'ActionToJavascript.jsx' file in the xtools/Apps/ folder
• Copy 'ActionToJavascript.jsx' into Adobe Photoshop 2022/Preset/Scripts/ folder
• Restart Photoshop and locate the new 'ActionToJavascript' script via [File] then [Scripts]
• Choose the required Action and where you want to save the translated Javascript file...
• Open the newly crea
...Copy link to clipboard
Copied
Ugly Javascript version:
sTT = stringIDToTypeID;
(ref1 = new ActionReference()).putProperty(sTT('property'), sTT('layerEffects'))
ref1.putEnumerated(sTT('layer'), sTT('ordinal'), sTT('targetEnum'));
(dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref1);
(dsc2 = new ActionDescriptor()).putUnitDouble(sTT('scale'), sTT('percentUnit'), 100);
(dsc3 = new ActionDescriptor()).putBoolean(sTT('enabled'), true)
dsc3.putBoolean(sTT('present'), true)
dsc3.putBoolean(sTT('showInDialog'), true)
dsc3.putEnumerated(sTT('mode'), sTT('blendMode'), sTT('multiply'));
(dsc4 = new ActionDescriptor()).putDouble(sTT('red'), 0)
dsc4.putDouble(sTT('grain'), 0)
dsc4.putDouble(sTT('blue'), 0)
dsc3.putObject(sTT('color'), sTT('RGBColor'), dsc4)
dsc3.putUnitDouble(sTT('opacity'), sTT('percentUnit'), 15)
dsc3.putBoolean(sTT('useGlobalAngle'), true)
dsc3.putUnitDouble(sTT('localLightingAngle'), sTT('angleUnit'), 90)
dsc3.putUnitDouble(sTT('distance'), sTT('pixelsUnit'), 0)
dsc3.putUnitDouble(sTT('chokeMatte'), sTT('pixelsUnit'), 0)
dsc3.putUnitDouble(sTT('blur'), sTT('pixelsUnit'), 35)
dsc3.putUnitDouble(sTT('noise'), sTT('percentUnit'), 0)
dsc3.putBoolean(sTT('antiAlias'), false);
(dsc5 = new ActionDescriptor()).putString(sTT('name'), 'Linear')
dsc3.putObject(sTT('transferSpec'), sTT('shapeCurveType'), dsc5)
dsc3.putBoolean(sTT('layerConceals'), true)
dsc2.putObject(sTT('dropShadow'), sTT('dropShadow'), dsc3)
dsc1.putObject(sTT('to'), sTT('layerEffects'), dsc2)
executeAction(sTT('set'), dsc1, DialogModes.NO);
Copy link to clipboard
Copied
Thanks for taking the time out to respond...
I was hoping there would be a way to directly translate the main bit of UXP code into Javascript. This way I could then extract other, more complex functions from Photoshop Actions, which are not supported by the applescript dictionary. Your answer does indeed apply a drop shadow to the current layer, but I'm looking for a much broader answer which could translate to other single step actions within Photsohop.
I have Alchemist installed but it looks like it's spitting out UXP code also... I also tried the Clean Listener script now bundled with Photoshop (as the ScriptListener is no longer supported), but it displays 'No handler found for event' as follows, on every line it returns:
// No handler found for event: 3487::invokeCommand
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thanks for all your help... When I get to the bottom of this I'll be sure to put the answer here! 🙂
Copy link to clipboard
Copied
So, after taking your advice I downloaded xbytor2's xtools and it seemed to do the job!
• Download the xtools zip from the xtools website
• Extract and locate the 'ActionToJavascript.jsx' file in the xtools/Apps/ folder
• Copy 'ActionToJavascript.jsx' into Adobe Photoshop 2022/Preset/Scripts/ folder
• Restart Photoshop and locate the new 'ActionToJavascript' script via [File] then [Scripts]
• Choose the required Action and where you want to save the translated Javascript file...
• Open the newly created Javascript file and trigger the Find/Replace function
• Using Find/Replace - Convert all double quotes to single quotes, select all, and copy selection
• Paste the updated javascript into Applescript...
tell application "Adobe Photoshop 2022"
activate
do javascript "<paste javascript from clipboard here>"
end tell
This now gives us the ability to store a Photoshop Action (as Javascript) in an Applescript, with the ability to tweak the variables where necessary! Thanks for your help Kukurykus and pointing me in the direction of xbytor2
Copy link to clipboard
Copied
Thanks for posting this, I have an answer here on how can I use the script from the xtools
to create a photoshop panel using UXP ? I'm not a coder but want to learn it with my current project.
Copy link to clipboard
Copied
yesserk4577066 I didn't understand much from what you wrote, from what I read are you creating a uxp panel using xtool?
Copy link to clipboard
Copied
xtools is for legacy ExtendScript, not for UXP panels or standalone UXP scripts.
In later versions of Photoshop one can enable developer mode or use Alchemist to extract batchPlay code for use with UXP.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more