I´m writing a Photoshop script to open some images and do some things on them. So far so good. I need the script to play a given Action previously recorded on Photoshop.
How can I invoke and play a Photoshop Action from a Javascript code?
I´m looking for something like:
app.actions["actionName"].play()
app.actions["actionName"].onComplete(function(){/*do stuff when finished*/})
(Translating the action into JS code is not an option for my application)
I´m writing a Photoshop script to open some images and do some things on them. So far so good. I need the script to play a given Action previously recorded on Photoshop.
How can I invoke and play a Photoshop Action from a Javascript code?
I´m looking for something like:
app.actions["actionName"].play()
app.actions["actionName"].onComplete(function(){/*do stuff when finished*/})
(Translating the action into JS code is not an option for my application)
Share Improve this question asked Feb 22, 2014 at 14:33 ButterDogButterDog 5,2456 gold badges45 silver badges62 bronze badges3 Answers
Reset to default 4The code i believe you are looking for is this:
app.doAction("ActionStep","ActionFile.ATN")
your gonna want to make sure the ATN file is already loaded into photoshops action palette, "ActionStep" is gonna be the name of the step you want to run, and "ActionFile.ATN" is the Action file that the step is located in.
you could go a bit further and even add in error handling
try{
//Code you want to execute
app.doAction("ActionStep","ActionFile.ATN")
}catch(e){
//If Code didn't execute then goes here, and executes code within this block
...Code...
}finally{
//executes this code immediately after try block, if error is thrown then is executed after catch block This block is optional and is not necessary.
...Code...
}
Running an action can be done with help from the xtools library avail here: http://ps-scripts.sourceforge/xtools.html I believe you want to look into the 'ActionEval' files. As to getting a notification when the action is plete - I'm not sure if playing the action will block execution of the script until it is finished. You'll have to test that for yourself.
You can use Plug-in ScriptingListener (https://helpx.adobe./pt/photoshop/kb/downloadable-plugins-and-content.html) to record your action and generate a script that will access your created action.
- Record your action
- Close photoshop and install the plugin
- Open photoshop and the "ScriptingListenerJS" file that will appear in your desktop
- play the action in your photoshop
- get the snippet code that will update inside your "ScriptingListenerJS" file.
- paste it into your extended script as a new function
- give a try
Check this example :
execAction("applyStrokeToImage", "ActionFile");
The implementation generated in ScriptingListenerJS:
function execAction(action, actionFile){
var idPly = charIDToTypeID( "Ply " );
var desc396 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref10 = new ActionReference();
var idActn = charIDToTypeID( "Actn" );
ref10.putName( idActn, action );
var idASet = charIDToTypeID( "ASet" );
ref10.putName( idASet, actionFile );
desc396.putReference( idnull, ref10 );
executeAction( idPly, desc396, DialogModes.NO );
}