问题
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)
回答1:
The 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...
}
回答2:
Running an action can be done with help from the xtools library avail here: http://ps-scripts.sourceforge.net/xtools.html I believe you want to look into the 'ActionEval' files. As to getting a notification when the action is complete - 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.
来源:https://stackoverflow.com/questions/21955699/running-a-photoshop-action-from-a-javascript-script