简体   繁体   中英

Running a Photoshop “Action” from a Javascript Script

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)

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...
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM