Running a Photoshop “Action” from a Javascript Script

…衆ロ難τιáo~ 提交于 2021-02-07 10:15:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!