【Photoshop JS脚本】jsx运行动作的几种方法

分类专栏: # Photoshop 脚本
最后发布:2020-11-04 11:48:48首次发布:2020-11-04 11:48:48
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
版权

1.动作已经存在PS动作面板,直接播放

app.doAction(“Action 2”,“Set 2”);

动作管理器用法

  1. play_action("默认动作", "存储为 Photoshop PDF")
  2. //Examples of using:
  3. //play_action("Set 1", "Action 1") // Perform the whole action// 执行整个动作
  4. //play_action("Set 1", "Action 1", 4, true) // Complete all from the beginning of the command number 4// 从命令编号4 的开头全部完成
  5. //play_action("Set 1", "Action 1", 5, false) // Will execute only command number 5// 仅执行命令编号5
  6. // cmd_number - the index of the command, ( starts from 1 )
  7. function play_action(set, action, cmd_number, allow_continue)
  8. {
  9. try
  10. {
  11. var d = new ActionDescriptor();
  12. var r = new ActionReference();
  13. if (typeof(cmd_number) == "number") r.putIndex( charIDToTypeID( "Cmnd" ), cmd_number );
  14. r.putName( charIDToTypeID( "Actn" ), action );
  15. r.putName( charIDToTypeID( "ASet" ), set );
  16. d.putReference( charIDToTypeID( "null" ), r );
  17. if (typeof(allow_continue) == "boolean") d.putBoolean( charIDToTypeID( "Cntn" ), allow_continue );
  18. executeAction( charIDToTypeID( "Ply " ), d, DialogModes.NO );
  19. }
  20. catch(e) { alert(e); }
  21. }

2.动作不存在,先加载进PS动作面板在播放

  1. app.load(File("C:\\2.atn"));
  2. app.doAction(“Action 2”,“Set 2”);

3.动作不存在,不加载进PS动作面板,直接播放

  1. app.bringToFront();
  2. /*************************************************
  3. Play a specific action contained in an actions file (.atn), without the need to load the file in the Actions Palette.
  4. http://www.tonton-pixel.com/JSON%20Action%20Manager/jsDoc/symbols/jamActions.html
  5. Utility script using the "JSON Action Manager" scripting library.
  6. © 2011-2015 Michel MARIANI.
  7. ******************************************************/
  8. //------------------------------------------------------------------------------
  9. // jamActions.jsxinc v4.4 (minified)
  10. if(typeof jamActions!=='object')
  11. {
  12. var jamActions={};
  13. (function()
  14. {
  15. jamActions.isActionsFile=function(file)
  16. {return(file.type==='8BAC')||file.name.match(/\.atn$/i);};
  17. jamActions.isActionsPalette=function(file)
  18. {return((file.type==='8BPF')&&file.name.match(/^Actions Palette$/i))||file.name.match(/^Actions Palette.psp$/i);};
  19. function readBEInt(file,byteCount)
  20. {var bytes=file.read(byteCount);
  21. var intValue=0;
  22. for(var index=0;index<byteCount;index++) {intValue=(intValue<<8)+bytes.charCodeAt(index);}
  23. return intValue;}
  24. function readBytes(file,byteCount)
  25. {return file.read(byteCount);}
  26. function readByteString(file)
  27. {var stringLength=readBEInt(file,4);
  28. return readBytes(file,stringLength);}
  29. function readUnicodeString(file) {
  30. var unicodeString="";
  31. var unicodeLength=readBEInt(file,4);
  32. for(var index=0;index<unicodeLength;index++)
  33. {var unicodeChar=readBEInt(file,2);
  34. if(unicodeChar!==0)
  35. {unicodeString+=String.fromCharCode(unicodeChar);}}
  36. return unicodeString;} function readEventId(file)
  37. {var eventId=0;var eventType=readBytes(file,4);
  38. switch(eventType) {
  39. case'TEXT':eventId=app.stringIDToTypeID(readByteString(file));break;
  40. case'long':eventId=app.charIDToTypeID(readBytes(file,4));break;
  41. default:throw new Error("[jamActions readEventId] Unrecognized event type: '"+eventType+"'");break;}
  42. return eventId;} function skipDouble(file) {file.seek(8,1);}
  43. function skipDoubles(file,doubleCount)
  44. {file.seek(doubleCount*8,1);}
  45. function skipInt8(file) {file.seek(1,1);}
  46. function skipInt16(file) {file.seek(2,1);}
  47. function skipInt32(file) {file.seek(4,1);}
  48. function skipInt64(file) {file.seek(8,1);}
  49. function skipBytes(file,byteCount) {file.seek(byteCount,1);}
  50. function skipByteString(file) {
  51. var stringLength=readBEInt(file,4);skipBytes(file,stringLength);}
  52. function skipUnicodeString(file) {
  53. var unicodeLength=readBEInt(file,4);skipBytes(file,unicodeLength*2);}
  54. function skipId(file) {
  55. var idLength=readBEInt(file,4);
  56. if(idLength) {skipBytes(file,idLength);} else {skipBytes(file,4);}}
  57. function skipClass(file) {skipUnicodeString(file);skipId(file);}
  58. function skipObject(file) {skipClass(file);
  59. var itemCount=readBEInt(file,4);
  60. for(var itemIndex=0;itemIndex<itemCount;itemIndex++) {skipId(file);skipItem(file);}}
  61. function skipList(file) {var itemCount=readBEInt(file,4);for(var itemIndex=0;itemIndex<itemCount;itemIndex++) {skipItem(file);}} function skipItem(file) {var typeId=readBytes(file,4);switch(typeId) {case'obj ':skipReference(file);break;case'Objc':case'GlbO':skipObject(file);break;case'type':case'GlbC':skipClass(file);
  62. break;case'VlLs':skipList(file);break;case'doub':skipDouble(file);break;case'UntF':skipBytes(file,4);skipDouble(file);break;case'TEXT':skipUnicodeString(file);break;case'enum':skipId(file);skipId(file);break;case'long':skipInt32(file);break;case'comp':skipInt64(file);break;case'bool':skipInt8(file);break;case'alis':
  63. skipByteString(file);break;case'Pth ':skipByteString(file);break;case'tdta':skipByteString(file);break;case'ObAr':var objCount=readBEInt(file,4);skipClass(file);var itemCount=readBEInt(file,4);for(var itemIndex=0;itemIndex<itemCount;itemIndex++) {skipId(file);skipInt32(file);skipInt32(file);
  64. var doublesCount=readBEInt(file,4);skipDoubles(file,doublesCount);} break;default:throw new Error("[jamActions skipItem] Unrecognized item type: '"+typeId+"'");break;}} function skipReference(file) {var itemCount=readBEInt(file,4);for(var itemIndex=0;itemIndex<itemCount;itemIndex++)
  65. {var formId=readBytes(file,4);skipClass(file);switch(formId) {case'Clss':break;case'prop':skipId(file);break;case'Enmr':skipId(file);skipId(file);break;case'rele':skipInt32(file);break;case'Idnt':skipInt32(file);break;case'indx':skipInt32(file);break;case'name':skipUnicodeString(file);
  66. break;default:throw new Error("[jamActions skipReference] Unrecognized item form: '"+formId+"'");break;}}} jamActions.readActionDescriptor=function(file,insertVersionPrefix) {var versionPrefix="\x00\x00\x00\x10";var start=file.tell();if(!insertVersionPrefix) {
  67. if(file.read(4)===versionPrefix) {versionPrefix="";} else {throw new Error('[jamActions.readActionDescriptor] Unrecognized version prefix');}} skipObject(file);var end=file.tell();file.seek(start,0);var stream=versionPrefix+file.read(end-start);
  68. var actionDescriptor=new ActionDescriptor();actionDescriptor.fromStream(stream);return actionDescriptor;};jamActions.dataFromActionsFile=function(actionsFile,isPalette) {var that=this;function parseActionSet(file) {
  69. var actionSet={};actionSet.name=localize(readUnicodeString(file));actionSet.expanded=(readBEInt(file,1)!==0);var actionCount=readBEInt(file,4);actionSet.actions=[];for(var actionIndex=0;actionIndex<actionCount;actionIndex++) {
  70. var action={};action.functionKey=readBEInt(file,2);action.shiftKey=(readBEInt(file,1)!==0);action.commandKey=(readBEInt(file,1)!==0);action.colorIndex=readBEInt(file,2);action.name=localize(readUnicodeString(file));action.expanded=(readBEInt(file,1)!==0);
  71. var commandCount=readBEInt(file,4);action.commands=[];for(var commandIndex=0;commandIndex<commandCount;commandIndex++) {var command={};command.expanded=(readBEInt(file,1)!==0);command.enabled=(readBEInt(file,1)!==0);command.withDialog=(readBEInt(file,1)!==0);
  72. command.dialogOptions=readBEInt(file,1);command.eventId=readEventId(file);command.dictionaryName=readByteString(file);if(readBEInt(file,4)!==0) {command.actionDescriptor=that.readActionDescriptor(file,true);} action.commands.push(command);} actionSet.actions.push(action);}
  73. return actionSet;} var file;if(typeof actionsFile==='string') {file=new File(actionsFile);} else if(actionsFile instanceof File) {file=actionsFile;} else {throw new Error('[jamActions.dataFromActionsFile] Invalid argument');} var fileData;if(file.open("r")) {try {file.encoding='BINARY';
  74. var fileVersion=readBEInt(file,4);if(fileVersion===16) {fileData={};fileData.version=fileVersion;if(isPalette) {fileData.actionSets=[];var actionSetCount=readBEInt(file,4);for(var actionSetIndex=0;actionSetIndex<actionSetCount;actionSetIndex++) {fileData.actionSets.push(parseActionSet(file));}}
  75. else {fileData.actionSet=parseActionSet(file);}} else {fileData="Unsupported actions file version: "+fileVersion;}} catch(e) {fileData=e.message;} finally {file.close();}} else {fileData="Cannot open file";} return fileData;};jamActions.isLocalPlayCommand=function(command,actionSetName) {
  76. var localPlayCommand=null;if(command.eventId===app.stringIDToTypeID("play")) {var targetId=app.stringIDToTypeID("target");if(command.actionDescriptor.hasKey(targetId)) {var localReference=command.actionDescriptor.getReference(targetId);do {try{
  77. var desiredClassId=localReference.getDesiredClass();}catch(e){break;} switch(desiredClassId) {case app.stringIDToTypeID("command"):var localCommandIndex=localReference.getIndex()-1;break;case app.stringIDToTypeID("action"):var localActionName=localReference.getName();break;
  78. case app.stringIDToTypeID("actionSet"):var localActionSetName=localReference.getName();break;} localReference=localReference.getContainer();} while(localReference);} var continueId=app.stringIDToTypeID("continue");
  79. if(command.actionDescriptor.hasKey(continueId)) {var localContinue=command.actionDescriptor.getBoolean(continueId);} if((typeof localActionSetName!=='undefined')&&(localActionSetName===actionSetName)) {localPlayCommand=[localActionName,localCommandIndex,localContinue];}}
  80. return localPlayCommand;};jamActions.determineDialogMode=function(command) {var dialogMode;switch(command.dialogOptions) {case 0:dialogMode=command.withDialog?DialogModes.ALL:DialogModes.NO;break;case 2:dialogMode=DialogModes.NO;break;case 1:case 3:dialogMode=DialogModes.ALL;break;}
  81. return dialogMode;} var globalCommandHandler=null;jamActions.setCommandHandler=function(commandHandler) {globalCommandHandler=commandHandler;};jamActions.traverseAction=function(actionSet,actionLocator,fromCommandIndex,continuePlay) {function handleCommands(commands) {
  82. var commandMax=(continuePlay)?commands.length:fromCommandIndex+1;for(var commandIndex=fromCommandIndex;commandIndex<commandMax;commandIndex++) {if(globalCommandHandler!==null) {globalCommandHandler(commands[commandIndex]);}}} if(typeof fromCommandIndex==='undefined')
  83. {fromCommandIndex=0;continuePlay=true;} var actions=actionSet.actions;if(typeof actionLocator==='string') {var actionName=actionLocator;for(var actionIndex=0;actionIndex<actions.length;actionIndex++) {var action=actions[actionIndex];if(action.name===actionName) {handleCommands(action.commands);break;}}}
  84. else if(typeof actionLocator==='number') {var actionIndex=actionLocator;if((actionIndex>=0)&&(actionIndex<actions.length)) {handleCommands(actions[actionIndex].commands);}}};}());}
  85. //------------------------------------------------------------------------------
  86. if(documents.length){
  87. Folder.current = new Folder ("~/Desktop/"); //Location of actionset folder.
  88. var actionsFilePath = "组 1.atn"; //Name of atn file.
  89. var ActionName = "动作 1"; //Name of the action within the action set.
  90. var fileData = jamActions.dataFromActionsFile (actionsFilePath);
  91. if (typeof fileData === 'string')
  92. {
  93. alert (fileData + "\n" + "Actions file: “" + actionsFilePath + "”");
  94. }
  95. else
  96. {
  97. function executeCommand (command,ActionName)
  98. {
  99. if (command.enabled)
  100. {
  101. var dialogMode = jamActions.determineDialogMode (command);
  102. app.executeAction (command.eventId, command.actionDescriptor, dialogMode);
  103. }
  104. }
  105. jamActions.setCommandHandler (executeCommand);
  106. jamActions.traverseAction (fileData.actionSet, ActionName);
  107. };
  108. };

 

(0)

相关推荐

  • 判断Input上传文件类型,文件大小

    判断input上传文件类型,文件大小.input获取的size为字节,判断大小的时候需要把限制大小转换为字节 //input标签添加Onchange事件 <input type="fi ...

  • layui table 行点击事件与列点击事件冲突

    问题描述: 工具栏的点击事件,会冒泡到行点击事件中,原打算阻止事件冒泡 ,结果失败,阻止不了,索性不用layui官网的工具栏tool和行row监听事件. table: <table id=&qu ...

  • 【Photoshop JS脚本】jsx如何操作excel

    jsx需要借助js开源库来操作excel.github地址:SheetJS 可能你会奇怪这是这是浏览器JS操作excel,并不能用于Photoshop.你只要找到xlsx.extendscript.j ...

  • 【Photoshop JS脚本】jsx如何读取二进制

    分类专栏: # Photoshop 脚本 最后发布:2020-11-04 11:52:59首次发布:2020-11-04 11:52:59 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA ...

  • 【Photoshop JS脚本】打开URL

    【Photoshop JS脚本】打开URL

  • 【Photoshop JS脚本】按键检测

    分类专栏: # Photoshop 脚本 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net ...

  • 改善下蹲动作的9种方法

    文章思路: 蹲不下去,不应该是中国人的问题呀,因为中国人都会"亚洲蹲"呀!显然这并非事实,我看过"信誓旦旦"的纪录片,让各个国家的男性女性做"亚洲蹲& ...

  • Win10运行菜单在哪?Win10运行怎么打开两种方法

    尽管最新的Win10回归了开始菜单,不过开始运行菜单依旧是隐藏的,以至于很多朋友,找不到Win10运行在哪.运行命令框在电脑日常操作中起到十分重要的作用,比如进入注册表.CMD命苦窗口.远程桌面等等都 ...

  • C#调用python脚本并传递参数的一种方法

    最近正好用python做了一个程序,由于是没有UI界面,使用起来没那么方便,同事建议将他做一个UI界面,方便操作,但又由于不想搞什么QT或者是Tkinter(太麻烦,其实真正的原因是我更擅长C#,手动 ...

  • chrome扩展程序开发/chrome运行本地JS脚本

    Chrome浏览器插件–Talend API Tester–Api测试插件推荐 Talend API Tester–Api测试插件推荐Chrome浏览器插件–Talend API Tester–Api ...

  • Linux系统Shell脚本如何运行?linux操作系统

    Shell脚本语言很适合用于处理纯文本类型的数据,而Linux系统中几乎所有的配置文件.日志文件以及绝大多数的启动文件都是纯文本类型的文件.因此,学好Shell脚本语言,能够更好的操作Linux系统. ...