/* Convert AM Code to JSON... "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. automate JSON Action Manager Code Utility */ //------------------------------------------------------------------------------ // File: Convert AM Code to JSON.js // Version: 4.1 // Release Date: 2015-11-24 // Copyright: © 2011-2015 Michel MARIANI // Licence: GPL //------------------------------------------------------------------------------ // 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 . //------------------------------------------------------------------------------ // 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 conflictingStringIdStrs) {stringIdStr=conflictingStringIdStrs[charIdStr];}}} return[charIdStr,stringIdStr];};jamEngine.equivalentUniIdStrs=function(uniIdStr1,uniIdStr2) {return this.uniIdStrToId(uniIdStr1)===this.uniIdStrToId(uniIdStr2);};function putInReference(ref,containers) {if(containers.constructor===Array) {var count=containers.length;for(var i=0;i":ref.putClass(desiredClassId);break;case"":var enumerated=that.parseCompact(value);ref.putEnumerated(desiredClassId,that.uniIdStrToId(enumerated[0]),that.uniIdStrToId(enumerated[1]));break;case"":ref.putIdentifier(desiredClassId,value);break;case"":ref.putIndex(desiredClassId,value);break;case"":ref.putName(desiredClassId,value);break;case"":ref.putOffset(desiredClassId,value);break;case"":ref.putProperty(desiredClassId,that.uniIdStrToId(value));break;default:throw new Error("[jamEngine putInReference] Unknown reference form: "+form);break;}}} else {throw new Error("[jamEngine putInReference] JavaScript array expected");}} function putInList(list,items) {if(items.constructor===Array) {var count=items.length;for(var i=0;i":list.putBoolean(value);break;case"":list.putClass(that.uniIdStrToId(value));break;case"":list.putData(value);break;case"":list.putDouble(value);break;case"":var enumerated=that.parseCompact(value);list.putEnumerated(that.uniIdStrToId(enumerated[0]),that.uniIdStrToId(enumerated[1]));break;case"":list.putInteger(value);break;case"":list.putLargeInteger(value);break;case"":var actionList=new ActionList();putInList(actionList,value);list.putList(actionList);break;case"":var object=that.parseCompact(value);if(object[1]) {var actionDescriptor=new ActionDescriptor();putInDescriptor(actionDescriptor,object[1]);list.putObject(that.uniIdStrToId(object[0]),actionDescriptor);} else {list.putClass(that.uniIdStrToId(object[0]));} break;case"":var fileRef=new File(value);list.putPath(fileRef);break;case"":var actionReference=new ActionReference();putInReference(actionReference,value);list.putReference(actionReference);break;case"":list.putString(value);break;case"":var unitDouble=that.parseCompact(value);list.putUnitDouble(that.uniIdStrToId(unitDouble[0]),unitDouble[1]);break;default:throw new Error("[jamEngine putInList] Unknown list type: "+type);break;}}} else {throw new Error("[jamEngine putInList] JavaScript array expected");}} function putInDescriptor(desc,members) {if(members.constructor===Object) {for(var key in members) {if(members.hasOwnProperty(key)) {var keyID=that.uniIdStrToId(key);var member=that.parseCompact(members[key]);var type=member[0];var value=member[1];switch(type) {case"":desc.putBoolean(keyID,value);break;case"":desc.putClass(keyID,that.uniIdStrToId(value));break;case"":desc.putData(keyID,value);break;case"":desc.putDouble(keyID,value);break;case"":var enumerated=that.parseCompact(value);desc.putEnumerated(keyID,that.uniIdStrToId(enumerated[0]),that.uniIdStrToId(enumerated[1]));break;case"":desc.putInteger(keyID,value);break;case"":desc.putLargeInteger(keyID,value);break;case"":var actionList=new ActionList();putInList(actionList,value);desc.putList(keyID,actionList);break;case"":var object=that.parseCompact(value);if(object[1]) {var actionDescriptor=new ActionDescriptor();putInDescriptor(actionDescriptor,object[1]);desc.putObject(keyID,that.uniIdStrToId(object[0]),actionDescriptor);} else {desc.putClass(keyID,that.uniIdStrToId(object[0]));} break;case"":var fileRef=new File(value);desc.putPath(keyID,fileRef);break;case"":var actionReference=new ActionReference();putInReference(actionReference,value);desc.putReference(keyID,actionReference);break;case"":desc.putString(keyID,value);break;case"":var unitDouble=that.parseCompact(value);desc.putUnitDouble(keyID,that.uniIdStrToId(unitDouble[0]),unitDouble[1]);break;default:throw new Error("[jamEngine putInDescriptor] Unknown descriptor type: "+type);break;}}}} else {throw new Error("[jamEngine putInDescriptor] JavaScript object expected");}} var contextRules={"'Algn'":{"":{"bevelEmboss":"align","frameFX":"align","gradientFill":"align","gradientLayer":"align","patternFill":"align","patternLayer":"align"},"":"align","":"alignment"},"'AntA'":{"":"antiAliasedPICTAcquire","":"antiAlias"},"'BckL'":{"":"backgroundLayer","":"backgroundLevel"},"'BlcG'":{"":"blackGenerationType","":"blackGenerationCurve"},"'BlcL'":{"":{"'GEfc'":"blackLevel","CMYKSetup":"blackLimit"},"":{"reticulation":"blackLevel"}},"'Blks'":{"":{"colors":"blacks","extrudeType":"blocks"}},"'BlrM'":{"":"blurMethod","":"blurMore","":"blurMethod"},"'BrgC'":{"":"brightnessContrast","":"brightnessContrast"},"'BrsD'":{"":"brushesDefine","":"brushDetail"},"'Brsh'":{"":"brush","":"brushes"},"'Clcl'":{"":"calculation","":"calculations","":"calculation"},"'ClrP'":{"":{"'GEft'":"coloredPencil"},"":"colorPalette","":"coloredPencil"},"'Cnst'":{"":{"channelMatrix":"constant"},"":"constrain"},"'CntC'":{"":{"'GEft'":"conteCrayon"},"":"conteCrayon","":"centerCropMarks"},"'Cntr'":{"":{"'GEfc'":"contrast","brightnessContrast":"contrast","document":"center","polygon":"center","quadrilateral":"center"},"":{"adaptCorrect":"contrast","brightnessEvent":"contrast","grain":"contrast","halftoneScreen":"contrast","sumie":"contrast","tornEdges":"contrast","waterPaper":"contrast"},"":"center"},"'CrtD'":{"":"createDuplicate","":"createDroplet"},"'CstP'":{"":"customPhosphors","":"customPalette"},"'Cstm'":{"":"customPattern","":"custom","":"custom"},"'Drkn'":{"":"darken","":"darkness"},"'Dstr'":{"":{"'GEfc'":"distortion"},"":{"glass":"distortion","addNoise":"distribution"},"":"distribution","":"distort","":"distribute"},"'Dstt'":{"":"desaturate","":"desaturate","":"destWhiteMax"},"'FlIn'":{"":{"fillColor":"fillInverse","menuItemType":"fileInfo"},"":"fileInfo","":"fileInfo"},"'Gd '":{"":"guide","":"good"},"'GnrP'":{"":"preferencesClass","":"generalPreferences","":"generalPrefs"},"'GrSt'":{"":"graySetup","":"grainStippled","":"graySetup"},"'Grdn'":{"":"gradientClassEvent","":"gradientClassEvent","":"gridMinor"},"'Grn '":{"":{"'GEft'":"grain"},"":{"'GEfc'":"grain","RGBColor":"green","blackAndWhite":"green","channelMatrix":"green","channelMixer":"green"},"":{"blackAndWhite":"green","channelMixer":"green","filmGrain":"grain"},"":"green","":"grain"},"'Grns'":{"":"greens","":"graininess"},"'HstP'":{"":"historyPreferences","":"historyPrefs"},"'HstS'":{"":"historyState","":"historyStateSourceType"},"'ImgP'":{"":"imagePoint","":"imageCachePreferences"},"'In '":{"":"stampIn","":"in"},"'IntW'":{"":"intersectWith","":"interfaceWhite"},"'Intr'":{"":{"shapeOperation":"intersect"},"":{"GIFFormat":"interlace","SaveForWeb":"interlace","application":"interfaceIconFrameDimmed","computedBrush":"interpolation","dBrush":"interpolation","gradientClassEvent":"interpolation","photoshopEPSFormat":"interpolation","sampledBrush":"interpolation"},"":{"convertMode":"interpolation","imageSize":"interpolation","transform":"interpolation"},"":"intersect"},"'JPEG'":{"":"JPEGFormat","":"JPEG"},"'LghD'":{"":"lightDirection","":"lightDirectional","":"lightDirection"},"'LghO'":{"":{"diffuseMode":"lightenOnly","lightType":"lightOmni"}},"'LghS'":{"":"lightSource","":"lightSpot","":"lightSource"},"'Lns '":{"":"lens","":"lines","":"lens"},"'Mgnt'":{"":{"channel":"magenta","colors":"magentas","guideGridColor":"magenta"},"":"magenta"},"'MrgL'":{"":"mergedLayers","":"mergeLayers"},"'Mxm '":{"":"maximumQuality","":"maximum","":"maximum"},"'NTSC'":{"":"NTSC","":"NTSCColors"},"'NmbL'":{"":{"'GEfc'":"numberOfLevels","document":"numberOfLayers"},"":{"cutout":"numberOfLevels"}},"'PlgP'":{"":"pluginPrefs","":"pluginPicker","":"pluginPrefs"},"'Pncl'":{"":"pencilEraser","":"pencilWidth"},"'Pnt '":{"":{"textType":"point"},"":"point","":"paint"},"'Prsp'":{"":"perspective","":"perspectiveIndex"},"'PrvM'":{"":"previewMagenta","":"previewMacThumbnail"},"'Pstr'":{"":"posterize","":"posterize","":"posterization"},"'RGBS'":{"":"RGBSetupSource","":"RGBSetup"},"'Rds '":{"":"reds","":"radius"},"'ScrD'":{"":"screenDot","":"scratchDisks"},"'ShdI'":{"":{"'GEfc'":"shadowIntensity"},"":{"watercolor":"shadowIntensity"},"":"shadingIntensity"},"'ShpC'":{"":{"application":"shapingCurve"},"":"shapingCurve","":"shapeCurveType"},"'ShrE'":{"":"sharpenEdges","":"shearEd"},"'Shrp'":{"":"sharpen","":"sharpness"},"'SplC'":{"":"splitChannels","":"supplementalCategories"},"'Spot'":{"":"spotColor","":"spot"},"'SprS'":{"":{"'GEft'":"sprayedStrokes"},"":"separationSetup","":"sprayedStrokes"},"'StrL'":{"":"strokeLocation","":"strokeLength"},"'Strt'":{"":{"currentToolOptions":"saturation","fileNamingRules":"start","HSBColorClass":"saturation","hueSatAdjustment":"saturation","hueSatAdjustmentV2":"saturation","lineClass":"start","range":"start","vibrance":"saturation"},"":{"replaceColor":"saturation","variations":"saturation","vibrance":"saturation"},"":"saturation"},"'TEXT'":{"":"textType","":"textType"},"'TIFF'":{"":"TIFFFormat","":"TIFF"},"'TglO'":{"":"toggleOptionsPalette","":"toggleOthers"},"'TrnG'":{"":{"application":"transparencyGrid","transparencyPrefs":"transparencyGridSize"},"":"transparencyGridSize","":"transparencyGamutPreferences"},"'TrnS'":{"":{"bevelEmboss":"transparencyShape","dropShadow":"transparencyShape","innerGlow":"transparencyShape","innerShadow":"transparencyShape","outerGlow":"transparencyShape"},"":"transparencyStop","":"transferSpec"},"'Trns'":{"":"transparent","":"transparency"},"'TxtC'":{"":{"'GEfc'":"textureCoverage","textLayer":"textClickPoint"},"":{"underpainting":"textureCoverage"}},"'TxtF'":{"":"textureFill","":"textureFile"},"'UsrM'":{"":"userMaskOptions","":"userMaskEnabled"},"'null'":{"":"null","":"null","":"null","":"target"}};function getFromId(context,parentContext) {var uniIdStr;var kind=context[0];var id=context[1];if(id":if((parentContext[0]==="")&&(""in rule)) {resolvedIdStr=resolveIdStr(rule[""]);} else if((parentContext[0]==="")&&(""in rule)) {resolvedIdStr=resolveIdStr(rule[""]);} break;case"":if((parentContext[0]==="")&&(""in rule)) {resolvedIdStr=resolveIdStr(rule[""]);} break;}} if(resolvedIdStr!=="") {uniIdStr=resolvedIdStr;} else if(kind in rule) {uniIdStr=rule[kind];}} else {var stringIDStr=app.typeIDToStringID(id);if(stringIDStr!=="") {uniIdStr=stringIDStr;}}}} return uniIdStr;} var incompatiblePlatformPath="";var getEventId=app.stringIDToTypeID("get");var targetKeyId=app.stringIDToTypeID("target");var propertyClassId=app.stringIDToTypeID("property");function getFromReference(ref) {var propertyId=0;var arr=[];do {try{var desiredClassId=ref.getDesiredClass();}catch(e){break;} if(propertyId!==0) {var propertyCompact=that.buildCompact("",getFromId(["",propertyId],["",desiredClassId]));arr.push(that.buildCompact(getFromId(["",propertyClassId]),propertyCompact));propertyId=0;} var desiredCompact;var aFormID=ref.getForm();switch(aFormID) {case ReferenceFormType.CLASSTYPE:desiredCompact=that.buildCompact("",null);break;case ReferenceFormType.ENUMERATED:var enumTypeContext=["",ref.getEnumeratedType()];var enumValueContext=["",ref.getEnumeratedValue()];desiredCompact=that.buildCompact("",that.buildCompact(getFromId(enumTypeContext),getFromId(enumValueContext,enumTypeContext)));break;case ReferenceFormType.IDENTIFIER:desiredCompact=that.buildCompact("",ref.getIdentifier());break;case ReferenceFormType.INDEX:desiredCompact=that.buildCompact("",ref.getIndex());break;case ReferenceFormType.NAME:desiredCompact=that.buildCompact("",ref.getName());break;case ReferenceFormType.OFFSET:desiredCompact=that.buildCompact("",ref.getOffset());break;case ReferenceFormType.PROPERTY:if(desiredClassId===propertyClassId) {propertyId=ref.getProperty();} else {desiredCompact=that.buildCompact("",getFromId(["",ref.getProperty()],["",desiredClassId]));} break;default:throw new Error("[jamEngine getFromReference] Unknown reference form type: "+aFormID);break;} if(desiredClassId!==propertyClassId) {arr.push(that.buildCompact(getFromId(["",desiredClassId]),desiredCompact));} ref=ref.getContainer();} while(ref);return arr;} function getFromList(list) {var arr=[];var itemCount=list.count;for(var itemIndex=0;itemIndex",list.getBoolean(itemIndex));break;case DescValueType.CLASSTYPE:itemCompact=that.buildCompact("",getFromId(["",list.getClass(itemIndex)]));break;case DescValueType.DOUBLETYPE:itemCompact=that.buildCompact("",list.getDouble(itemIndex));break;case DescValueType.ENUMERATEDTYPE:var enumTypeContext=["",list.getEnumerationType(itemIndex)];var enumValueContext=["",list.getEnumerationValue(itemIndex)];itemCompact=that.buildCompact("",that.buildCompact(getFromId(enumTypeContext),getFromId(enumValueContext,enumTypeContext)));break;case DescValueType.INTEGERTYPE:itemCompact=that.buildCompact("",list.getInteger(itemIndex));break;case DescValueType.LISTTYPE:itemCompact=that.buildCompact("",getFromList(list.getList(itemIndex)));break;case DescValueType.OBJECTTYPE:var objectTypeContext=["",list.getObjectType(itemIndex)];var objectValue=list.getObjectValue(itemIndex);itemCompact=that.buildCompact("",that.buildCompact(getFromId(objectTypeContext),getFromDescriptor(objectValue,objectTypeContext)));break;case DescValueType.ALIASTYPE:try {var fileRef=list.getPath(itemIndex);itemCompact=that.buildCompact("",fileRef.fsName);} catch(e) {itemCompact=that.buildCompact("",incompatiblePlatformPath);} break;case DescValueType.REFERENCETYPE:itemCompact=that.buildCompact("",getFromReference(list.getReference(itemIndex)));break;case DescValueType.STRINGTYPE:itemCompact=that.buildCompact("",list.getString(itemIndex));break;case DescValueType.UNITDOUBLE:var unitTypeContext=["",list.getUnitDoubleType(itemIndex)];var doubleValue=list.getUnitDoubleValue(itemIndex);itemCompact=that.buildCompact("",that.buildCompact(getFromId(unitTypeContext),doubleValue));break;default:var isRawType;var isLargeIntegerType;try{isRawType=(typeID===DescValueType.RAWTYPE);}catch(e){} try{isLargeIntegerType=(typeID===DescValueType.LARGEINTEGERTYPE);}catch(e){} if(isRawType) {itemCompact=that.buildCompact("",list.getData(itemIndex));} else if(isLargeIntegerType) {itemCompact=that.buildCompact("",list.getLargeInteger(itemIndex));} else {throw new Error("[jamEngine getFromList] Unknown descriptor value type: "+typeID);} break;} arr[itemIndex]=itemCompact;} return arr;} function getFromDescriptor(desc,parentContext) {if(desc) {var obj={};var keyCount;try{keyCount=desc.count;}catch(e){return null;} for(var keyIndex=0;keyIndex",keyID],parentContext);var keyCompact;var typeID;try{typeID=desc.getType(keyID);}catch(e){continue;} switch(typeID) {case DescValueType.BOOLEANTYPE:keyCompact=that.buildCompact("",desc.getBoolean(keyID));break;case DescValueType.CLASSTYPE:keyCompact=that.buildCompact("",getFromId(["",desc.getClass(keyID)]));break;case DescValueType.DOUBLETYPE:keyCompact=that.buildCompact("",desc.getDouble(keyID));break;case DescValueType.ENUMERATEDTYPE:var enumTypeContext=["",desc.getEnumerationType(keyID)];var enumValueContext=["",desc.getEnumerationValue(keyID)];keyCompact=that.buildCompact("",that.buildCompact(getFromId(enumTypeContext),getFromId(enumValueContext,enumTypeContext)));break;case DescValueType.INTEGERTYPE:keyCompact=that.buildCompact("",desc.getInteger(keyID));break;case DescValueType.LISTTYPE:keyCompact=that.buildCompact("",getFromList(desc.getList(keyID)));break;case DescValueType.OBJECTTYPE:var objectTypeContext=["",desc.getObjectType(keyID)];var objectValue=desc.getObjectValue(keyID);keyCompact=that.buildCompact("",that.buildCompact(getFromId(objectTypeContext),getFromDescriptor(objectValue,objectTypeContext)));break;case DescValueType.ALIASTYPE:try {var fileRef=desc.getPath(keyID);keyCompact=that.buildCompact("",fileRef.fsName);} catch(e) {keyCompact=that.buildCompact("",incompatiblePlatformPath);} break;case DescValueType.REFERENCETYPE:keyCompact=that.buildCompact("",getFromReference(desc.getReference(keyID)));break;case DescValueType.STRINGTYPE:keyCompact=that.buildCompact("",desc.getString(keyID));break;case DescValueType.UNITDOUBLE:var unitTypeContext=["",desc.getUnitDoubleType(keyID)];var doubleValue=desc.getUnitDoubleValue(keyID);keyCompact=that.buildCompact("",that.buildCompact(getFromId(unitTypeContext),doubleValue));break;default:var isRawType;var isLargeIntegerType;try{isRawType=(typeID===DescValueType.RAWTYPE);}catch(e){} try{isLargeIntegerType=(typeID===DescValueType.LARGEINTEGERTYPE);}catch(e){} if(isRawType) {keyCompact=that.buildCompact("",desc.getData(keyID));} else if(isLargeIntegerType) {keyCompact=that.buildCompact("",desc.getLargeInteger(keyID));} else {throw new Error("[jamEngine getFromDescriptor] Unknown descriptor value type: "+typeID);} break;} obj[keyString]=keyCompact;} return obj;} else {return null;}} jamEngine.jsonToActionDescriptor=function(descriptorObj) {that=this;var actionDescriptor;if(descriptorObj) {actionDescriptor=new ActionDescriptor();putInDescriptor(actionDescriptor,descriptorObj);} return actionDescriptor;};jamEngine.jsonToActionReference=function(referenceArr) {that=this;var actionReference;if(referenceArr) {actionReference=new ActionReference();putInReference(actionReference,referenceArr);} return actionReference;};jamEngine.eventIdAndActionDescriptorToJson=function(eventId,actionDescriptor) {that=this;var eventIdContext=["",eventId];return{"":getFromId(eventIdContext),"":getFromDescriptor(actionDescriptor,eventIdContext)};};jamEngine.classIdAndActionDescriptorToJson=function(classId,actionDescriptor) {that=this;var classIdContext=["",classId];return{"":getFromId(classIdContext),"":getFromDescriptor(actionDescriptor,classIdContext)};};jamEngine.actionReferenceToJson=function(actionReference) {that=this;return getFromReference(actionReference);};function getReferenceClassId(ref) {classId=0;do {try{var desiredClassId=ref.getDesiredClass();}catch(e){break;} if(desiredClassId!==propertyClassId) {classId=desiredClassId;break;} ref=ref.getContainer();} while(ref);return classId;} jamEngine.jsonPlay=function(eventUniIdStr,descriptorObj,displayDialogs) {var eventId=this.uniIdStrToId(eventUniIdStr);var desc=this.jsonToActionDescriptor(descriptorObj);var parentContext;if(eventId===getEventId) {var ref=desc.getReference(targetKeyId);parentContext=["",getReferenceClassId(ref)];} else {parentContext=["",eventId];} return getFromDescriptor(app.executeAction(eventId,desc,displayDialogs||this.displayDialogs),parentContext);};jamEngine.jsonGet=function(referenceArr) {var ref=this.jsonToActionReference(referenceArr);return getFromDescriptor(app.executeActionGet(ref),["",getReferenceClassId(ref)]);};jamEngine.normalizeJsonItem=function(item,options) {function normalizeItem(item) {var explicit=that.parseCompact(item);var type=explicit[0];var value=explicit[1];var normalizedValue;switch(type) {case"":case"":case"":case"":case"":case"":case"":case"":case"":case"":case"":normalizedValue=value;break;case"":normalizedValue=value&&getFromId(["",that.uniIdStrToId(value)]);break;case"":var enumerated=that.parseCompact(value);var enumTypeContext=["",that.uniIdStrToId(enumerated[0])];var enumValueContext=["",that.uniIdStrToId(enumerated[1])];normalizedValue=that.buildCompact(getFromId(enumTypeContext),getFromId(enumValueContext,enumTypeContext));break;case"":normalizedValue=[];for(var i=0;i":var object=that.parseCompact(value);var objectClassContext=["",that.uniIdStrToId(object[0])];var objectDescriptor=object[1];var normalizedDescriptor;if(objectDescriptor===null) {normalizedDescriptor=null;} else {normalizedDescriptor={};for(var key in objectDescriptor) {if(objectDescriptor.hasOwnProperty(key)) {var objectKeyContext=["",that.uniIdStrToId(key)];normalizedDescriptor[getFromId(objectKeyContext,objectClassContext)]=normalizeItem(objectDescriptor[key]);}}} normalizedValue=that.buildCompact(getFromId(objectClassContext),normalizedDescriptor);break;case"":normalizedValue=getFromId(["",that.uniIdStrToId(value)]);break;case"":normalizedValue=[];for(var i=0;i",that.uniIdStrToId(container[0])]),normalizeItem(container[1])));} break;case"":var unitDouble=that.parseCompact(value);var unitTypeContext=["",that.uniIdStrToId(unitDouble[0])];normalizedValue=that.buildCompact(getFromId(unitTypeContext),unitDouble[1]);break;default:throw new Error("[jamEngine.normalizeJsonItem] Unknown item type: "+type);break;} return that.buildCompact(type,normalizedValue);} that=this;var saveMeaningfulIds=this.meaningfulIds;var saveParseFriendly=this.parseFriendly;if(options&&(options.constructor===Object)) {if(typeof options.meaningfulIds!=='undefined') {this.meaningfulIds=options.meaningfulIds;} if(typeof options.parseFriendly!=='undefined') {this.parseFriendly=options.parseFriendly;}} var normalizedItem=normalizeItem(item);this.meaningfulIds=saveMeaningfulIds;this.parseFriendly=saveParseFriendly;return normalizedItem;};function simplifyRef(ref) {var simplifiedRef=[];for(var i=0;i":case"":case"":case"":case"":case"":simplifiedElement[desiredClass]=value[1];break;default:throw new Error("[jamEngine simplifyRef] Unexpected element form: "+form);break;} simplifiedRef.push(simplifiedElement);} return simplifiedRef;} function simplifyItem(item,hook) {var simplifiedItem;var type=item[0];var value=item[1];switch(type) {case"":case"":case"":case"":case"":case"":case"":case"":simplifiedItem=value;break;case"":simplifiedItem=simplifyList(value,hook);break;case"":case"":simplifiedItem=value[1];break;case"":simplifiedItem=simplifyDesc(value[1],hook);break;case"":simplifiedItem=simplifyRef(value);break;default:throw new Error("[jamEngine simplifyItem] Unexpected item type: "+type);break;} return simplifiedItem;} function simplifyList(list,hook) {var simplifiedList=[];for(var i=0;i"]=typeValue[0];explicit[valueKey||""]=typeValue[1];return explicit;};jamEngine.buildCompact=function(type,value) {var compact;if(typeof type==='string') {if(this.parseFriendly) {compact=[type,value];} else {compact={};compact[type]=value;}} else {throw new Error("[jamEngine.buildCompact] String expected");} return compact;};jamEngine.explicitToCompact=function(explicit,typeKey,valueKey) {var compact;if(explicit.constructor===Object) {compact=this.buildCompact(explicit[typeKey||""],explicit[valueKey||""]);} else {throw new Error("[jamEngine.explicitToCompact] JavaScript object expected");} return compact;};for(var charIdStr in conflictingStringIdStrs) {if(conflictingStringIdStrs.hasOwnProperty(charIdStr)) {var stringIdStrs=conflictingStringIdStrs[charIdStr];for(var index=stringIdStrs.length-1;index>=0;index--) {var stringIdStr=stringIdStrs[index];if(!(app.charIDToTypeID(charIdStr.substring(1,5))===app.stringIDToTypeID(stringIdStr))) {stringIdStrs.splice(index,1);}} if(stringIdStrs.length<2) {delete conflictingStringIdStrs[charIdStr];}}} for(var charIdStr in contextRules) {if(contextRules.hasOwnProperty(charIdStr)) {if(charIdStr in conflictingStringIdStrs) {var rule=contextRules[charIdStr];for(var kind in rule) {if(rule.hasOwnProperty(kind)) {switch(kind) {case"":case"":case"":case"":case"":case"":if(app.charIDToTypeID(charIdStr.substring(1,5))!=app.stringIDToTypeID(rule[kind])) {throw new Error("[jamEngine] "+"\""+charIdStr+"\" and \""+rule[kind]+"\" are not equivalent ID strings");} break;case"":case"":case"":for(var parent in rule[kind]) {if(rule[kind].hasOwnProperty(parent)) {if(app.charIDToTypeID(charIdStr.substring(1,5))!=app.stringIDToTypeID(rule[kind][parent])) {throw new Error("[jamEngine] "+"\""+charIdStr+"\" and \""+rule[kind][parent]+"\" are not equivalent ID strings");}}} break;}}}} else {delete contextRules[charIdStr];}}}}());} // 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\u070F\u17B4\u17B5\u200C-\u200F\u2028-\u202F\u2060-\u206F\uFEFF\uFFF0-\uFFFF]/g;var meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};var gap;var indent;var prefixIndent;function quote(string) {escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return(typeof c==='string')?c:'\\u'+('0000'+a.charCodeAt(0).toString(16).toUpperCase()).slice(-4);})+'"':'"'+string+'"';} function str(value) {var i;var k;var v;var mind=gap;var partial;switch(typeof value) {case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value) {return'null';} gap+=indent;partial=[];if(value.constructor===Array) {for(i=0;i","fontList"]],["application",["",["ordinal","targetEnum"]]]]);var fontPostScriptNameArr=resultDescriptorObj["fontList"][1][1]["fontPostScriptName"][1];for(var i=0;i",action]],["actionSet",["",actionSet]]]);var found=true;} catch(e) {var found=false;} if(!found) {jamEngine.jsonPlay("open",{"target":["",actionsFilePath]});}};jamUtils.loadActionSet=function(actionSet,actionsFilePath) {try {jamEngine.jsonGet([["actionSet",["",actionSet]]]);var found=true;} catch(e) {var found=false;} if(!found) {jamEngine.jsonPlay("open",{"target":["",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",["","presetManager"]],["application",["",["ordinal","targetEnum"]]]]);var presetManagerArr=resultDescriptorObj["presetManager"][1];for(var i=0;i",presetFilePath]});} else {jamEngine.jsonPlay ("set",{"target":["",[["property",["",presetProperty]],["application",["",["ordinal","targetEnum"]]]]],"to":["",presetFilePath],"append":["",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) {clone=[];for(var i=0;i"][jsonCustomOptionsStringKey][""],true)} catch(e) {var customOptions={};} jamEngine.meaningfulIds=saveMeaningfulIds;jamEngine.parseFriendly=saveParseFriendly;return this.mergeData(customOptions,defaultOptions);};jamUtils.putCustomOptions=function(signature,customOptions,persistent) {var descriptorObj={};descriptorObj[jsonCustomOptionsStringKey]=["",jamJSON.stringify(customOptions)];app.putCustomOptions(signature,jamEngine.jsonToActionDescriptor(descriptorObj),persistent);};jamUtils.eraseCustomOptions=function(signature) {app.eraseCustomOptions(signature);};jamUtils.dataToHexaString=function(dataString,lowercase) {var hexaDigits=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"];var hexaString="";var length=dataString.length;for(var index=0;index=0x00)&&(dataByte<=0xFF)) {hexaString+=hexaDigits[(dataByte&0xF0)>>4]+hexaDigits[dataByte&0x0F];} else {throw new Error("[jamUtils.dataToHexaString] Invalid data string");}} if(lowercase) {hexaString=hexaString.toLowerCase();} return hexaString;};jamUtils.hexaToDataString=function(hexaString) {var dataString="";var length=hexaString.length;if(((length%2)===0)&&(/^[0-9A-Fa-f]*$/.test(hexaString))) {for(var index=0;index"], tab, tab) + ',\n'; resultText += jamJSON.stringify (playObj[""], 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."); } //------------------------------------------------------------------------------