admin 管理员组文章数量: 1086019
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 );
}
本文标签: automationRunning a Photoshop quotActionquot from a Javascript ScriptStack Overflow
版权声明:本文标题:automation - Running a Photoshop "Action" from a Javascript Script - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1743992817a2515045.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论