518 lines
62 KiB
JavaScript
518 lines
62 KiB
JavaScript
|
|
/*
|
||
|
|
|
||
|
|
<javascriptresource>
|
||
|
|
<name>Convert AM Code to JSON...</name>
|
||
|
|
<about>"Convert AM Code to JSON" v4.1
|
||
|
|
|
||
|
|
Convert plain Action Manager code copied from the ScriptingListenerJS.log file into executable code using the JSON Action Manager scripting library.
|
||
|
|
|
||
|
|
Utility script using the "JSON Action Manager" scripting library.
|
||
|
|
© 2011-2015 Michel MARIANI.
|
||
|
|
</about>
|
||
|
|
<menu>automate</menu>
|
||
|
|
<category>JSON Action Manager Code Utility</category>
|
||
|
|
</javascriptresource>
|
||
|
|
|
||
|
|
*/
|
||
|
|
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
// File: Convert AM Code to JSON.js
|
||
|
|
// Version: 4.1
|
||
|
|
// Release Date: 2015-11-24
|
||
|
|
// Copyright: © 2011-2015 Michel MARIANI <http://www.tonton-pixel.com/blog/>
|
||
|
|
// Licence: GPL <http://www.gnu.org/licenses/gpl.html>
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
// This program is free software: you can redistribute it and/or modify
|
||
|
|
// it under the terms of the GNU General Public License as published by
|
||
|
|
// the Free Software Foundation, either version 3 of the License, or
|
||
|
|
// (at your option) any later version.
|
||
|
|
//
|
||
|
|
// This program is distributed in the hope that it will be useful,
|
||
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
|
// GNU General Public License for more details.
|
||
|
|
//
|
||
|
|
// You should have received a copy of the GNU General Public License
|
||
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
// Version History:
|
||
|
|
// 4.1:
|
||
|
|
// - Used new version 4.4.4 of jamEngine scripting library module.
|
||
|
|
// 4.0:
|
||
|
|
// - Used new version 4.4.1 of scripting library modules.
|
||
|
|
// 3.9:
|
||
|
|
// - Used new version 4.0 of scripting library modules.
|
||
|
|
// 3.8:
|
||
|
|
// - Used new version of jamEngine module.
|
||
|
|
// 3.7:
|
||
|
|
// - Used new version of scripting library modules.
|
||
|
|
// 3.6:
|
||
|
|
// - Used new version of jamEngine (updated disambiguating rules table for CS6).
|
||
|
|
// - Used new version of scripting library modules.
|
||
|
|
// 3.5:
|
||
|
|
// - Used jamUtils.writeTextFile () and jamUtils.readTextFile () in replacement
|
||
|
|
// of custom code.
|
||
|
|
// 3.4:
|
||
|
|
// - Added 'TEXT' Mac OS type to newly created text files.
|
||
|
|
// 3.3:
|
||
|
|
// - Modified the order of options in dialog box.
|
||
|
|
// - Used new version of scripting library modules.
|
||
|
|
// 3.2:
|
||
|
|
// - Incremented version number to keep in sync with scripting library modules.
|
||
|
|
// 3.1:
|
||
|
|
// - Incremented version number to keep in sync with scripting library modules.
|
||
|
|
// 3.0:
|
||
|
|
// - Applied the redefined JSON AM Reference format.
|
||
|
|
// 2.0:
|
||
|
|
// - Simplified About string in resource header.
|
||
|
|
// - Added Clear button in dialog.
|
||
|
|
// - Improved the availability of monospaced fonts
|
||
|
|
// - Used more parse-friendly JSON compact format.
|
||
|
|
// - Handled jamEngine global options.
|
||
|
|
// - Renamed script "Convert AM to JSON" to "Convert AM Code to JSON".
|
||
|
|
// - Made stand-alone (using inline minified headers).
|
||
|
|
// 1.0:
|
||
|
|
// - Initial release.
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
// jamEngine.jsxinc v4.4.4 (minified)
|
||
|
|
if(typeof jamEngine!=='object') {var jamEngine={};(function() {var that;jamEngine.meaningfulIds=false;jamEngine.parseFriendly=false;jamEngine.displayDialogs=DialogModes.ERROR;var conflictingStringIdStrs={"'Algn'":["align","alignment"],"'AntA'":["antiAlias","antiAliasedPICTAcquire"],"'BckL'":["backgroundLayer","backgroundLevel"],"'BlcG'":["blackGenerationType","blackGenerationCurve"],"'BlcL'":["blackLevel","blackLimit"],"'Blks'":["blacks","blocks"],"'BlrM'":["blurMethod","blurMore"],"'BrgC'":["brightnessEvent","brightnessContrast"],"'BrsD'":["brushDetail","brushesDefine"],"'Brsh'":["brush","brushes"],"'Clcl'":["calculation","calculations"],"'ClrP'":["colorPalette","coloredPencil"],"'Cnst'":["constant","constrain"],"'CntC'":["centerCropMarks","conteCrayon"],"'Cntr'":["center","contrast"],"'CrtD'":["createDroplet","createDuplicate"],"'CstP'":["customPalette","customPhosphors"],"'Cstm'":["custom","customPattern"],"'Drkn'":["darken","darkness"],"'Dstr'":["distort","distortion","distribute","distribution"],"'Dstt'":["desaturate","destWhiteMax"],"'FlIn'":["fileInfo","fillInverse"],"'Gd '":["good","guide"],"'GnrP'":["generalPreferences","generalPrefs","preferencesClass"],"'GrSt'":["grainStippled","graySetup"],"'Grdn'":["gradientClassEvent","gridMinor"],"'Grn '":["grain","green"],"'Grns'":["graininess","greens"],"'HstP'":["historyPreferences","historyPrefs"],"'HstS'":["historyState","historyStateSourceType"],"'ImgP'":["imageCachePreferences","imagePoint"],"'In '":["in","stampIn"],"'IntW'":["interfaceWhite","intersectWith"],"'Intr'":["interfaceIconFrameDimmed","interlace","interpolation","intersect"],"'JPEG'":["JPEG","JPEGFormat"],"'LghD'":["lightDirection","lightDirectional"],"'LghO'":["lightOmni","lightenOnly"],"'LghS'":["lightSource","lightSpot"],"'Lns '":["lens","lines"],"'Mgnt'":["magenta","magentas"],"'MrgL'":["mergeLayers","mergedLayers"],"'Mxm '":["maximum","maximumQuality"],"'NTSC'":["NTSC","NTSCColors"],"'NmbL'":["numberOfLayers","numberOfLevels"],"'PlgP'":["pluginPicker","pluginPrefs"],"'Pncl'":["pencilEraser","pencilWidth"],"'Pnt '":["paint","point"],"'Prsp'":["perspective","perspectiveIndex"],"'PrvM'":["previewMacThumbnail","previewMagenta"],"'Pstr'":["posterization","posterize"],"'RGBS'":["RGBSetup","RGBSetupSource"],"'Rds '":["radius","reds"],"'ScrD'":["scratchDisks","screenDot"],"'ShdI'":["shadingIntensity","shadowIntensity"],"'ShpC'":["shapeCurveType","shapingCurve"],"'ShrE'":["sharpenEdges","shearEd"],"'Shrp'":["sharpen","sharpness"],"'SplC'":["splitChannels","supplementalCategories"],"'Spot'":["spot","spotColor"],"'SprS'":["separationSetup","sprayedStrokes"],"'StrL'":["strokeLength","strokeLocation"],"'Strt'":["saturation","start"],"'TEXT'":["char","textType"],"'TIFF'":["TIFF","TIFFFormat"],"'TglO'":["toggleOptionsPalette","toggleOthers"],"'TrnG'":["transparencyGamutPreferences","transparencyGrid","transparencyGridSize"],"'TrnS'":["transferSpec","transparencyShape","transparencyStop"],"'Trns'":["transparency","transparent"],"'TxtC'":["textClickPoint","textureCoverage"],"'TxtF'":["textureFile","textureFill"],"'UsrM'":["userMaskEnabled","userMaskOptions"],"'c@#^'":["inherits","pInherits"],"'comp'":["comp","sInt64"],"'doub'":["floatType","IEEE64BitFloatingPoint","longFloat"],"'long'":["integer","longInteger","sInt32"],"'magn'":["magnitude","uInt32"],"'null'":["null","target"],"'shor'":["sInt16","sMInt","shortInteger"],"'sing'":["IEEE32BitFloatingPoint","sMFloat","shortFloat"]};jamEngine.getConflictingStringIdStrs=function(charIdStr) {return conflictingStringIdStrs[charIdStr]||null;};jamEngine.uniIdStrToId=function(uniIdStr) {var id=0;if(typeof uniIdStr==='string') {if((uniIdStr.length===(1+4+1))&&(uniIdStr.charAt(0)==="'")&&(uniIdStr.charAt(5)==="'")) {id=app.charIDToTypeID(uniIdStr.substring(1,5));} else {id=app.stringIDToTypeID(uniIdStr);}} return id;};var smallestHashValue=app.charIDToTypeID(" ");jamEngine.idToUniIdStrs=function(id) {var charIdStr="";var stringIdStr=app.typeIDToStringID(id);if(id>=smallestHashValue) {charIdStr="'"+app.typeIDToCharID(id)+"'";if(stringIdStr!=="") {if(charIdStr in conflicting
|
||
|
|
// jamJSON.jsxinc v4.4 (minified)
|
||
|
|
if(typeof jamJSON!=='object') {var jamJSON={};(function() {var state;var stack;var container;var key;var value;var escapes={'\\':'\\','"':'"','/':'/','t':'\t','n':'\n','r':'\r','f':'\f','b':'\b'};var action={'{':{go:function() {stack.push({state:'ok'});container={};state='firstokey';},ovalue:function() {stack.push({container:container,state:'ocomma',key:key});container={};state='firstokey';},firstavalue:function() {stack.push({container:container,state:'acomma'});container={};state='firstokey';},avalue:function() {stack.push({container:container,state:'acomma'});container={};state='firstokey';}},'}':{firstokey:function() {var pop=stack.pop();value=container;container=pop.container;key=pop.key;state=pop.state;},ocomma:function() {var pop=stack.pop();container[key]=value;value=container;container=pop.container;key=pop.key;state=pop.state;}},'[':{go:function() {stack.push({state:'ok'});container=[];state='firstavalue';},ovalue:function() {stack.push({container:container,state:'ocomma',key:key});container=[];state='firstavalue';},firstavalue:function() {stack.push({container:container,state:'acomma'});container=[];state='firstavalue';},avalue:function() {stack.push({container:container,state:'acomma'});container=[];state='firstavalue';}},']':{firstavalue:function() {var pop=stack.pop();value=container;container=pop.container;key=pop.key;state=pop.state;},acomma:function() {var pop=stack.pop();container.push(value);value=container;container=pop.container;key=pop.key;state=pop.state;}},':':{colon:function() {if(container.hasOwnProperty(key)) {throw new SyntaxError("[jamJSON.parse] Duplicate key: “"+key+"”");} state='ovalue';}},',':{ocomma:function() {container[key]=value;state='okey';},acomma:function() {container.push(value);state='avalue';}},'true':{go:function() {value=true;state='ok';},ovalue:function() {value=true;state='ocomma';},firstavalue:function() {value=true;state='acomma';},avalue:function() {value=true;state='acomma';}},'false':{go:function() {value=false;state='ok';},ovalue:function() {value=false;state='ocomma';},firstavalue:function() {value=false;state='acomma';},avalue:function() {value=false;state='acomma';}},'null':{go:function() {value=null;state='ok';},ovalue:function() {value=null;state='ocomma';},firstavalue:function() {value=null;state='acomma';},avalue:function() {value=null;state='acomma';}}};var number={go:function() {state='ok';},ovalue:function() {state='ocomma';},firstavalue:function() {state='acomma';},avalue:function() {state='acomma';}};var string={go:function() {state='ok';},firstokey:function() {key=value;state='colon';},okey:function() {key=value;state='colon';},ovalue:function() {state='ocomma';},firstavalue:function() {state='acomma';},avalue:function() {state='acomma';}};var commentFunc=function(){};function debackslashify(text) {return text.replace(/\\(?:u(.{4})|([^u]))/g,function(a,b,c){return(b)?String.fromCharCode(parseInt(b,16)):escapes[c];});} jamJSON.parse=function(text,validate,allowComments) {if(validate) {var tx=/^[\x20\t\n\r]*(?:([,:\[\]{}]|true|false|null)|(-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+\-]?[0-9]+)?)|"((?:[^\r\n\t\\\"]|\\(?:["\\\/trnfb]|u[0-9a-fA-F]{4}))*)")/;var txc=/^[\x20\t\n\r]*(?:(\/(?:\/.*|\*(?:.|[\r\n])*?\*\/))|([,:\[\]{}]|true|false|null)|(-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+\-]?[0-9]+)?)|"((?:[^\r\n\t\\\"]|\\(?:["\\\/trnfb]|u[0-9a-fA-F]{4}))*)")/;var r;var i;var actionFunc;state='go';stack=[];try {while(true) {i=(allowComments)?1:0;r=(allowComments)?txc.exec(text):tx.exec(text);if(!r) {break;} if(allowComments&&r[1]) {actionFunc=commentFunc;} else if(r[i+1]) {actionFunc=action[r[i+1]][state];} else if(r[i+2]) {value=+r[i+2];actionFunc=number[state];} else {value=debackslashify(r[i+3]);actionFunc=string[state];} if(actionFunc) {actionFunc();text=text.slice(r[0].length);} else {break;}}} catch(e) {state=e;} if(state!=='ok'||/[^\x20\t\n\r]/.test(text)) {throw state instanceof SyntaxError?state:new SyntaxError("[jamJSON.parse] Invalid JSON");} return value;} else {return eval('('+text+')');}};var escapable=/[\\\"\x00-\x1F\x7F-\x9F\u00AD\u0600-\u0604
|
||
|
|
// jamUtils.jsxinc v4.4 (minified)
|
||
|
|
if(typeof jamUtils!=='object') {var jamUtils={};(function() {jamUtils.toDistanceUnit=function(amount,amountBasePerInch) {return(amount/amountBasePerInch)*72.0;};jamUtils.fromDistanceUnit=function(amount,amountBasePerInch) {return(amount/72.0)*amountBasePerInch;};jamUtils.fontExists=function(fontPostScriptName) {var useDOM=true;var found=false;if(useDOM) {for(var i=0;i<app.fonts.length;i++) {if(app.fonts[i].postScriptName===fontPostScriptName) {found=true;break;}}} else {var saveMeaningfulIds=jamEngine.meaningfulIds;var saveParseFriendly=jamEngine.parseFriendly;jamEngine.meaningfulIds=true;jamEngine.parseFriendly=true;var resultDescriptorObj=jamEngine.jsonGet ([["property",["<property>","fontList"]],["application",["<enumerated>",["ordinal","targetEnum"]]]]);var fontPostScriptNameArr=resultDescriptorObj["fontList"][1][1]["fontPostScriptName"][1];for(var i=0;i<fontPostScriptNameArr.length;i++) {if(fontPostScriptNameArr[i][1]===fontPostScriptName) {found=true;break;}} jamEngine.meaningfulIds=saveMeaningfulIds;jamEngine.parseFriendly=saveParseFriendly;} return found;};jamUtils.loadAction=function(action,actionSet,actionsFilePath) {try {jamEngine.jsonGet([["action",["<name>",action]],["actionSet",["<name>",actionSet]]]);var found=true;} catch(e) {var found=false;} if(!found) {jamEngine.jsonPlay("open",{"target":["<path>",actionsFilePath]});}};jamUtils.loadActionSet=function(actionSet,actionsFilePath) {try {jamEngine.jsonGet([["actionSet",["<name>",actionSet]]]);var found=true;} catch(e) {var found=false;} if(!found) {jamEngine.jsonPlay("open",{"target":["<path>",actionsFilePath]});}};jamUtils.loadPreset=function(presetProperty,presetName,presetFilePath) {var useDOM=false;var useOpen=true;var classes={"brush":"brush","colors":"color","gradientClassEvent":"gradientClassEvent","style":"styleClass","pattern":"'PttR'","shapingCurve":"shapingCurve","customShape":"customShape","toolPreset":"toolPreset"};var presetClass=classes[presetProperty];var saveMeaningfulIds=jamEngine.meaningfulIds;var saveParseFriendly=jamEngine.parseFriendly;jamEngine.meaningfulIds=true;jamEngine.parseFriendly=true;var found=false;var resultDescriptorObj=jamEngine.jsonGet ([["property",["<property>","presetManager"]],["application",["<enumerated>",["ordinal","targetEnum"]]]]);var presetManagerArr=resultDescriptorObj["presetManager"][1];for(var i=0;i<presetManagerArr.length;i++) {var presets=presetManagerArr[i][1];if(presets[0]===presetClass) {var presetsArr=presets[1]["name"][1];for(var j=0;j<presetsArr.length;j++) {if(presetsArr[j][1]===presetName) {found=true;break;}} break;}} if(!found) {if(useDOM) {app.load(new File(presetFilePath));} else if(useOpen) {jamEngine.jsonPlay("open",{"target":["<path>",presetFilePath]});} else {jamEngine.jsonPlay ("set",{"target":["<reference>",[["property",["<property>",presetProperty]],["application",["<enumerated>",["ordinal","targetEnum"]]]]],"to":["<path>",presetFilePath],"append":["<boolean>",true]});}} jamEngine.meaningfulIds=saveMeaningfulIds;jamEngine.parseFriendly=saveParseFriendly;};function getFileObject(file) {var fileObject;if(file instanceof File) {fileObject=file;} else if(typeof file==='string') {fileObject=new File(file);} else {throw new Error('[jamUtils getFileObject] Invalid argument');} return fileObject;} jamUtils.readTextFile=function(textFile) {var text=null;var file=getFileObject(textFile);if(file.open("r")) {text=file.read();file.close();} return text;};jamUtils.readJsonFile=function(jsonFile) {return jamJSON.parse(this.readTextFile(jsonFile),true);};jamUtils.writeTextFile=function(textFile,text) {var file=getFileObject(textFile);if(file.open('w','TEXT')) {file.encoding='UTF-8';file.lineFeed='unix';file.write('\uFEFF');file.write(text);file.close();}};jamUtils.writeJsonFile=function(jsonFile,data,space) {this.writeTextFile(jsonFile,jamJSON.stringify(data,space));};jamUtils.cloneData=function(data) {var clone;if(data===null) {clone=data;} else if(data.constructor===Object) {clone={};for(var k in data) {if(data.hasOwnProperty(k)) {clone[k]=this.cloneData(data[k]);}}} else if(data.constructor===Array)
|
||
|
|
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
var signature = "json-action-manager-convert-am-code-to-json-options";
|
||
|
|
|
||
|
|
var defaultAMCode =
|
||
|
|
'// =======================================================\
|
||
|
|
var id33 = charIDToTypeID( "Mk " );\
|
||
|
|
var desc8 = new ActionDescriptor();\
|
||
|
|
var id34 = charIDToTypeID( "null" );\
|
||
|
|
var ref2 = new ActionReference();\
|
||
|
|
var id35 = charIDToTypeID( "AdjL" );\
|
||
|
|
ref2.putClass( id35 );\
|
||
|
|
desc8.putReference( id34, ref2 );\
|
||
|
|
var id36 = charIDToTypeID( "Usng" );\
|
||
|
|
var desc9 = new ActionDescriptor();\
|
||
|
|
var id37 = charIDToTypeID( "Nm " );\
|
||
|
|
desc9.putString( id37, "Curves" );\
|
||
|
|
var id38 = charIDToTypeID( "Opct" );\
|
||
|
|
var id39 = charIDToTypeID( "#Prc" );\
|
||
|
|
desc9.putUnitDouble( id38, id39, 75.000000 );\
|
||
|
|
var id40 = charIDToTypeID( "Md " );\
|
||
|
|
var id41 = charIDToTypeID( "BlnM" );\
|
||
|
|
var id42 = charIDToTypeID( "SftL" );\
|
||
|
|
desc9.putEnumerated( id40, id41, id42 );\
|
||
|
|
var id43 = charIDToTypeID( "Type" );\
|
||
|
|
var desc10 = new ActionDescriptor();\
|
||
|
|
var id44 = charIDToTypeID( "Adjs" );\
|
||
|
|
var list2 = new ActionList();\
|
||
|
|
var desc11 = new ActionDescriptor();\
|
||
|
|
var id45 = charIDToTypeID( "Chnl" );\
|
||
|
|
var ref3 = new ActionReference();\
|
||
|
|
var id46 = charIDToTypeID( "Chnl" );\
|
||
|
|
var id47 = charIDToTypeID( "Chnl" );\
|
||
|
|
var id48 = charIDToTypeID( "Grn " );\
|
||
|
|
ref3.putEnumerated( id46, id47, id48 );\
|
||
|
|
desc11.putReference( id45, ref3 );\
|
||
|
|
var id49 = charIDToTypeID( "Crv " );\
|
||
|
|
var list3 = new ActionList();\
|
||
|
|
var desc12 = new ActionDescriptor();\
|
||
|
|
var id50 = charIDToTypeID( "Hrzn" );\
|
||
|
|
desc12.putDouble( id50, 0.000000 );\
|
||
|
|
var id51 = charIDToTypeID( "Vrtc" );\
|
||
|
|
desc12.putDouble( id51, 0.000000 );\
|
||
|
|
var id52 = charIDToTypeID( "Pnt " );\
|
||
|
|
list3.putObject( id52, desc12 );\
|
||
|
|
var desc13 = new ActionDescriptor();\
|
||
|
|
var id53 = charIDToTypeID( "Hrzn" );\
|
||
|
|
desc13.putDouble( id53, 178.000000 );\
|
||
|
|
var id54 = charIDToTypeID( "Vrtc" );\
|
||
|
|
desc13.putDouble( id54, 103.000000 );\
|
||
|
|
var id55 = charIDToTypeID( "Pnt " );\
|
||
|
|
list3.putObject( id55, desc13 );\
|
||
|
|
var desc14 = new ActionDescriptor();\
|
||
|
|
var id56 = charIDToTypeID( "Hrzn" );\
|
||
|
|
desc14.putDouble( id56, 255.000000 );\
|
||
|
|
var id57 = charIDToTypeID( "Vrtc" );\
|
||
|
|
desc14.putDouble( id57, 255.000000 );\
|
||
|
|
var id58 = charIDToTypeID( "Pnt " );\
|
||
|
|
list3.putObject( id58, desc14 );\
|
||
|
|
desc11.putList( id49, list3 );\
|
||
|
|
var id59 = charIDToTypeID( "CrvA" );\
|
||
|
|
list2.putObject( id59, desc11 );\
|
||
|
|
desc10.putList( id44, list2 );\
|
||
|
|
var id60 = charIDToTypeID( "Crvs" );\
|
||
|
|
desc9.putObject( id43, id60, desc10 );\
|
||
|
|
var id61 = charIDToTypeID( "AdjL" );\
|
||
|
|
desc8.putObject( id36, id61, desc9 );\
|
||
|
|
executeAction( id33, desc8, DialogModes.NO );\
|
||
|
|
';
|
||
|
|
|
||
|
|
var defaultOptions =
|
||
|
|
{
|
||
|
|
codeDefaultFile: "~/Desktop/am-code.js",
|
||
|
|
resultDefaultFile: "~/Desktop/json-code.js",
|
||
|
|
code: defaultAMCode,
|
||
|
|
meaningfulIds: false,
|
||
|
|
parseFriendly: false,
|
||
|
|
expandTabs: false,
|
||
|
|
dialog:
|
||
|
|
{
|
||
|
|
width: 1024,
|
||
|
|
height: 768,
|
||
|
|
x: 0,
|
||
|
|
y: 0
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
var openWithEditor = false;
|
||
|
|
var openParentFolder = false;
|
||
|
|
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
var filterEvents = false;
|
||
|
|
|
||
|
|
var processGet = true;
|
||
|
|
|
||
|
|
var includePathHeader = '//@includepath "~/JSON Action Manager/"';
|
||
|
|
var includeHeader = '//@include "jamEngine.jsxinc"';
|
||
|
|
var meaningfulIdsOption = 'jamEngine.meaningfulIds';
|
||
|
|
var parseFriendlyOption = 'jamEngine.parseFriendly';
|
||
|
|
var playFunctionCall = 'jamEngine.jsonPlay';
|
||
|
|
var getFunctionCall = 'jamEngine.jsonGet';
|
||
|
|
|
||
|
|
var tab;
|
||
|
|
|
||
|
|
var resultText;
|
||
|
|
|
||
|
|
var meaningfulIds;
|
||
|
|
var parseFriendly;
|
||
|
|
var expandTabs;
|
||
|
|
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
// Skip (filter out) purely informative and potentially recursive events
|
||
|
|
function filteredEvent (event)
|
||
|
|
{
|
||
|
|
var filtered = false;
|
||
|
|
switch (event)
|
||
|
|
{
|
||
|
|
case jamEngine.uniIdStrToId ("AdobeScriptAutomation Scripts"):
|
||
|
|
case jamEngine.uniIdStrToId ("notify"):
|
||
|
|
case jamEngine.uniIdStrToId ("stop"):
|
||
|
|
filtered = true;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
return filtered;
|
||
|
|
}
|
||
|
|
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
function newExecuteAction (event, descriptor, displayDialogs)
|
||
|
|
{
|
||
|
|
if (!(filterEvents && filteredEvent (event))) // If required, skip (filter out) some events
|
||
|
|
{
|
||
|
|
jamEngine.meaningfulIds = meaningfulIds;
|
||
|
|
jamEngine.parseFriendly = parseFriendly;
|
||
|
|
var playObj = jamEngine.eventIdAndActionDescriptorToJson (event, descriptor);
|
||
|
|
resultText += playFunctionCall + '\n';
|
||
|
|
resultText += '(\n';
|
||
|
|
resultText += jamJSON.stringify (playObj["<event>"], tab, tab) + ',\n';
|
||
|
|
resultText += jamJSON.stringify (playObj["<descriptor>"], tab, tab);
|
||
|
|
if (typeof displayDialogs !== 'undefined')
|
||
|
|
{
|
||
|
|
resultText += ',\n';
|
||
|
|
resultText += tab + displayDialogs;
|
||
|
|
}
|
||
|
|
resultText += '\n';
|
||
|
|
resultText += ');\n';
|
||
|
|
resultText += '\n';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
function newExecuteActionGet (reference)
|
||
|
|
{
|
||
|
|
if (processGet)
|
||
|
|
{
|
||
|
|
jamEngine.meaningfulIds = meaningfulIds;
|
||
|
|
jamEngine.parseFriendly = parseFriendly;
|
||
|
|
var referenceArr = jamEngine.actionReferenceToJson (reference);
|
||
|
|
resultText += getFunctionCall + '\n';
|
||
|
|
resultText += '(\n';
|
||
|
|
resultText += jamJSON.stringify (referenceArr, tab, tab);
|
||
|
|
resultText += '\n';
|
||
|
|
resultText += ');\n';
|
||
|
|
resultText += '\n';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
function displayDialog ()
|
||
|
|
{
|
||
|
|
// Get an available UI font among a list of favorites
|
||
|
|
function getAvailableUIFont (fontsArray)
|
||
|
|
{
|
||
|
|
// List all fonts available in Photoshop in JSON format
|
||
|
|
var fontsObj = { };
|
||
|
|
for (var i = 0; i < app.fonts.length; i++)
|
||
|
|
{
|
||
|
|
var family = app.fonts[i].family;
|
||
|
|
if (!(family in fontsObj))
|
||
|
|
{
|
||
|
|
fontsObj[family] = { };
|
||
|
|
}
|
||
|
|
fontsObj[family][app.fonts[i].style] =
|
||
|
|
{
|
||
|
|
"name": app.fonts[i].name
|
||
|
|
};
|
||
|
|
}
|
||
|
|
var availableFont;
|
||
|
|
var fontFamily;
|
||
|
|
var fontStyle;
|
||
|
|
var fontSize;
|
||
|
|
for (var i = 0; i < fontsArray.length; i++)
|
||
|
|
{
|
||
|
|
fontFamily = fontsArray[i][0];
|
||
|
|
if (fontFamily in fontsObj)
|
||
|
|
{
|
||
|
|
fontStyle = fontsArray[i][1];
|
||
|
|
if (fontStyle in fontsObj[fontFamily])
|
||
|
|
{
|
||
|
|
fontSize = fontsArray[i][2];
|
||
|
|
availableFont = ScriptUI.newFont (fontFamily, fontStyle, fontSize)
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return availableFont;
|
||
|
|
}
|
||
|
|
var monospacedFont =
|
||
|
|
getAvailableUIFont
|
||
|
|
(
|
||
|
|
[
|
||
|
|
[ "Monaco", "Regular", 12 ],
|
||
|
|
[ "Lucida Sans Typewriter", "Regular", 14 ],
|
||
|
|
[ "Courier", "Regular", 16 ],
|
||
|
|
[ "Courier New", "Regular", 14 ]
|
||
|
|
]
|
||
|
|
);
|
||
|
|
var codeDefaultFile = new File (customOptions.codeDefaultFile);
|
||
|
|
var resultDefaultFile = new File (customOptions.resultDefaultFile);
|
||
|
|
var dialog = new Window ('dialog', "Convert AM Code to JSON", undefined, { resizeable: true });
|
||
|
|
dialog.orientation = "column";
|
||
|
|
dialog.preferredSize.width = customOptions.dialog.width;
|
||
|
|
dialog.preferredSize.height = customOptions.dialog.height;
|
||
|
|
dialog.onResizing = function ()
|
||
|
|
{
|
||
|
|
this.layout.resize ();
|
||
|
|
};
|
||
|
|
executeAction = newExecuteAction;
|
||
|
|
app.executeAction = newExecuteAction;
|
||
|
|
executeActionGet = newExecuteActionGet;
|
||
|
|
app.executeActionGet = newExecuteActionGet;
|
||
|
|
function convertCode (resultArea)
|
||
|
|
{
|
||
|
|
meaningfulIds = meaningfulIdsCheck.value;
|
||
|
|
parseFriendly = parseFriendlyCheck.value;
|
||
|
|
expandTabs = expandTabsCheck.value;
|
||
|
|
resultArea.text = "";
|
||
|
|
resultText = "";
|
||
|
|
resultText += includePathHeader + '\n';
|
||
|
|
resultText += includeHeader + '\n';
|
||
|
|
resultText += '\n';
|
||
|
|
resultText += meaningfulIdsOption + ' = ' + (meaningfulIds ? 'true' : 'false') + ';\n';
|
||
|
|
resultText += parseFriendlyOption + ' = ' + (parseFriendly ? 'true' : 'false') + ';\n';
|
||
|
|
resultText += '\n';
|
||
|
|
tab = (expandTabs) ? ' ' : '\t';
|
||
|
|
try
|
||
|
|
{
|
||
|
|
eval (codeArea.text);
|
||
|
|
}
|
||
|
|
catch (e)
|
||
|
|
{
|
||
|
|
resultText = "[Invalid JavaScript code] " + e;
|
||
|
|
}
|
||
|
|
resultArea.text = resultText;
|
||
|
|
};
|
||
|
|
dialog.onShow = function ()
|
||
|
|
{
|
||
|
|
var x = customOptions.dialog.x;
|
||
|
|
var y = customOptions.dialog.y;
|
||
|
|
if ((x !== 0) || (y !== 0))
|
||
|
|
{
|
||
|
|
this.location.x = x;
|
||
|
|
this.location.y = y;
|
||
|
|
}
|
||
|
|
meaningfulIdsCheck.value = customOptions.meaningfulIds;
|
||
|
|
parseFriendlyCheck.value = customOptions.parseFriendly;
|
||
|
|
expandTabsCheck.value = customOptions.expandTabs;
|
||
|
|
codeArea.text = customOptions.code;
|
||
|
|
codeArea.active = true;
|
||
|
|
};
|
||
|
|
var AMGroup = dialog.add ('group');
|
||
|
|
AMGroup.orientation = "column";
|
||
|
|
AMGroup.alignment = [ "fill", "fill" ];
|
||
|
|
var codeArea = AMGroup.add ('edittext', undefined, "", { multiline: true });
|
||
|
|
codeArea.alignment = [ "fill", "fill" ];
|
||
|
|
codeArea.minimumSize = [ -1, 120 ];
|
||
|
|
if (monospacedFont)
|
||
|
|
{
|
||
|
|
codeArea.graphics.font = monospacedFont;
|
||
|
|
}
|
||
|
|
function pressed (k)
|
||
|
|
{
|
||
|
|
if ((k.keyName === "Tab") || (k.keyIdentifier === "Enter")) // *Not* (k.keyName === "Enter") !!
|
||
|
|
{
|
||
|
|
k.preventDefault ();
|
||
|
|
if (!k.target.properties.readonly)
|
||
|
|
{
|
||
|
|
k.target.textselection = (k.keyName === "Tab") ? '\t' : '\n';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
};
|
||
|
|
dialog.addEventListener ("keydown", pressed);
|
||
|
|
var textButtonsGroup = AMGroup.add ('group');
|
||
|
|
textButtonsGroup.alignment = [ "center", "bottom" ];
|
||
|
|
textButtonsGroup.orientation = "row";
|
||
|
|
textButtonsGroup.alignChildren = "fill";
|
||
|
|
var clearButton = textButtonsGroup.add ('button', undefined, 'Clear');
|
||
|
|
clearButton.alignment = [ "center", "center" ];
|
||
|
|
clearButton.onClick = function ()
|
||
|
|
{
|
||
|
|
resultArea.text = "";
|
||
|
|
codeArea.text = "";
|
||
|
|
codeArea.active = true;
|
||
|
|
};
|
||
|
|
var fileIn;
|
||
|
|
var fileOut;
|
||
|
|
var loadCodeButton = textButtonsGroup.add ('button', undefined, 'Load...');
|
||
|
|
loadCodeButton.onClick = function ()
|
||
|
|
{
|
||
|
|
fileIn = codeDefaultFile.openDlg ("Load AM code from file:");
|
||
|
|
if (fileIn)
|
||
|
|
{
|
||
|
|
codeArea.text = jamUtils.readTextFile (fileIn);
|
||
|
|
codeDefaultFile = fileIn;
|
||
|
|
}
|
||
|
|
codeArea.active = true;
|
||
|
|
};
|
||
|
|
var saveCodeButton = textButtonsGroup.add ('button', undefined, 'Save...');
|
||
|
|
saveCodeButton.onClick = function ()
|
||
|
|
{
|
||
|
|
fileOut = codeDefaultFile.saveDlg ("Save AM code to file:");
|
||
|
|
if (fileOut)
|
||
|
|
{
|
||
|
|
jamUtils.writeTextFile (fileOut, codeArea.text);
|
||
|
|
if (openWithEditor)
|
||
|
|
{
|
||
|
|
fileOut.execute ();
|
||
|
|
}
|
||
|
|
else if (openParentFolder)
|
||
|
|
{
|
||
|
|
fileOut.parent.execute ();
|
||
|
|
}
|
||
|
|
codeDefaultFile = fileOut;
|
||
|
|
}
|
||
|
|
codeArea.active = true;
|
||
|
|
};
|
||
|
|
var actionButtonsGroup = AMGroup.add ('group');
|
||
|
|
actionButtonsGroup.alignment = [ "center", "bottom" ];
|
||
|
|
actionButtonsGroup.orientation = "row";
|
||
|
|
actionButtonsGroup.alignChildren = "fill";
|
||
|
|
var optionsGroup = actionButtonsGroup.add ('group');
|
||
|
|
optionsGroup.orientation = "row";
|
||
|
|
optionsGroup.alignment = [ "right", "center" ];
|
||
|
|
var meaningfulIdsCheck = optionsGroup.add ('checkbox', undefined, 'Meaningful IDs');
|
||
|
|
var parseFriendlyCheck = optionsGroup.add ('checkbox', undefined, 'Parse-Friendly');
|
||
|
|
var expandTabsCheck = optionsGroup.add ('checkbox', undefined, 'Expand Tabs');
|
||
|
|
var convertGroup = AMGroup.add ('group');
|
||
|
|
var convertButton = convertGroup.add ('button', undefined, 'Convert');
|
||
|
|
convertButton.alignment = [ "center", "center" ];
|
||
|
|
convertButton.onClick = function ()
|
||
|
|
{
|
||
|
|
convertCode (resultArea);
|
||
|
|
};
|
||
|
|
var JSONGroup = dialog.add ('group');
|
||
|
|
JSONGroup.orientation = "column";
|
||
|
|
JSONGroup.alignment = [ "fill", "fill" ];
|
||
|
|
var resultArea = JSONGroup.add ('edittext', undefined, "", { multiline: true, readonly: true });
|
||
|
|
resultArea.alignment = [ "fill", "fill" ];
|
||
|
|
resultArea.minimumSize = [ -1, 120 ];
|
||
|
|
if (monospacedFont)
|
||
|
|
{
|
||
|
|
resultArea.graphics.font = monospacedFont;
|
||
|
|
}
|
||
|
|
var file;
|
||
|
|
var saveResultButton = JSONGroup.add ('button', undefined, 'Save...');
|
||
|
|
saveResultButton.alignment = [ "center", "bottom" ];
|
||
|
|
saveResultButton.onClick = function ()
|
||
|
|
{
|
||
|
|
file = resultDefaultFile.saveDlg ("Save JSON code to file:");
|
||
|
|
if (file)
|
||
|
|
{
|
||
|
|
jamUtils.writeTextFile (file, resultArea.text);
|
||
|
|
if (openWithEditor)
|
||
|
|
{
|
||
|
|
file.execute ();
|
||
|
|
}
|
||
|
|
else if (openParentFolder)
|
||
|
|
{
|
||
|
|
file.parent.execute ();
|
||
|
|
}
|
||
|
|
resultDefaultFile = file;
|
||
|
|
}
|
||
|
|
codeArea.active = true;
|
||
|
|
};
|
||
|
|
var modalButtonsGroup = dialog.add ('group');
|
||
|
|
modalButtonsGroup.alignment = [ "right", "bottom" ];
|
||
|
|
modalButtonsGroup.orientation = "row";
|
||
|
|
modalButtonsGroup.alignChildren = "fill";
|
||
|
|
var cancelButton = modalButtonsGroup.add ('button', undefined, 'Cancel', { name: "cancel" });
|
||
|
|
cancelButton.onClick = function ()
|
||
|
|
{
|
||
|
|
dialog.close (false);
|
||
|
|
};
|
||
|
|
var okButton = modalButtonsGroup.add ('button', undefined, 'OK', { name: "ok" });
|
||
|
|
okButton.onClick = function ()
|
||
|
|
{
|
||
|
|
customOptions.codeDefaultFile = codeDefaultFile.fsName;
|
||
|
|
customOptions.resultDefaultFile = resultDefaultFile.fsName;
|
||
|
|
customOptions.code = codeArea.text;
|
||
|
|
customOptions.meaningfulIds = meaningfulIdsCheck.value;
|
||
|
|
customOptions.parseFriendly = parseFriendlyCheck.value;
|
||
|
|
customOptions.expandTabs = expandTabsCheck.value;
|
||
|
|
customOptions.dialog.width = dialog.size.width;
|
||
|
|
customOptions.dialog.height = dialog.size.height;
|
||
|
|
customOptions.dialog.x = dialog.location.x;
|
||
|
|
customOptions.dialog.y = dialog.location.y;
|
||
|
|
dialog.close (true);
|
||
|
|
};
|
||
|
|
return dialog.show ();
|
||
|
|
}
|
||
|
|
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
var appVersion = parseInt (app.version);
|
||
|
|
// Requires: support for cut and paste, getCustomOptions (), putCustomOptions (), newFont (), addEventListener ("keydown"), preventDefault ()...
|
||
|
|
if (appVersion >= 11) // CS4 or later
|
||
|
|
{
|
||
|
|
var customOptions = jamUtils.getCustomOptions (signature, defaultOptions);
|
||
|
|
if (displayDialog ())
|
||
|
|
{
|
||
|
|
jamUtils.putCustomOptions (signature, customOptions, true);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
alert ("Sorry, this script requires Photoshop CS4 or later.");
|
||
|
|
}
|
||
|
|
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
|