├── LICENSE ├── README.md ├── example ├── descriptor-info-example.jsx └── helpers │ └── JSON.jsx └── jsx └── descriptor-info.jsx /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Javier Aroche 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Descriptor Info 2 | [![npm-image](https://img.shields.io/badge/Descriptor%20Info-v1.1.0-09bc00.svg)](https://github.com/JavierAroche/parse-action-descriptor-code) 3 | 4 | ## Description 5 | JSX module to recursively get all the properties in an `ActionDescriptor` used in Adobe applications. 6 | 7 | ## Usage 8 | 9 | **getProperties** 10 | 11 | Return complete Descriptor info in JSON format 12 | ```javascript 13 | /** 14 | * @param {Boolean} reference - return reference descriptors. Could slightly affect speed. Default = false. 15 | * @param {Boolean} extended - returns extended information about the descriptor. Default = false. 16 | * @param {Number} maxRawLimit - limits the max number of characters from a RAWTYPE descriptor. Default = 10000. 17 | * @param {Number} maxXMPLimit - limits the max number of characters from an XMPMetadataAsUTF8 property. Default = 10000. 18 | * @param {String} saveToFile - Saves the descriptor to a JSON file. Default = '~/Desktop/descriptor-info.json'. 19 | */ 20 | ``` 21 | 22 | **Sample code for getting Descriptor properties with getProperties** 23 | ```javascript 24 | // Include the JSON helper 25 | #include "./helpers/JSON.jsx" 26 | // Include the descriptor-info module 27 | #include "../jsx/descriptor-info.jsx" 28 | 29 | // ActionDescriptor example 30 | var ref = new ActionReference(); 31 | ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 32 | var desc = executeActionGet(ref); 33 | 34 | // Optional 35 | var descFlags = { 36 | reference : false, 37 | extended : false, 38 | maxRawLimit : 10000, 39 | maxXMPLimit : 100000, 40 | saveToFile: '~/Desktop/descriptor-info.json' 41 | }; 42 | 43 | // Retrieve its properties by running the getProperties function, passing the ActionDescriptor as a param 44 | var descObject = descriptorInfo.getProperties( desc, descFlags ); 45 | ``` 46 | 47 | 48 | **JSON returned for requested Descriptor info.** 49 | ```javascript 50 | { 51 | "name": "Layer 0", 52 | "color": "none", 53 | "visible": true, 54 | "mode": "normal", 55 | "opacity": 255, 56 | "layerID": 4, 57 | "itemIndex": 2, 58 | "count": 3, 59 | "preserveTransparency": false, 60 | "layerFXVisible": false, 61 | "globalAngle": 30, 62 | "background": false, 63 | "layerSection": "layerSectionContent", 64 | "layerLocking": { 65 | "protectTransparency": false, 66 | "protectComposite": false, 67 | "protectPosition": false, 68 | "protectAll": false 69 | }, 70 | "group": false, 71 | "targetChannels": [ 72 | { 73 | "typename": "ActionReference" 74 | }, 75 | { 76 | "typename": "ActionReference" 77 | }, 78 | { 79 | "typename": "ActionReference" 80 | } 81 | ], 82 | "visibleChannels": [ 83 | { 84 | "typename": "ActionReference" 85 | }, 86 | { 87 | "typename": "ActionReference" 88 | }, 89 | { 90 | "typename": "ActionReference" 91 | } 92 | ], 93 | "channelRestrictions": [ 94 | "red", 95 | "grain", 96 | "blue" 97 | ], 98 | "fillOpacity": 255, 99 | "hasUserMask": false, 100 | "hasVectorMask": false, 101 | "proportionalScaling": false, 102 | "layerKind": 5, 103 | "hasFilterMask": false, 104 | "userMaskDensity": 255, 105 | "userMaskFeather": 0, 106 | "vectorMaskDensity": 255, 107 | "vectorMaskFeather": 0, 108 | "bounds": { 109 | "top": -51, 110 | "left": -104, 111 | "bottom": 1599, 112 | "right": 2312, 113 | "width": 2416, 114 | "height": 1650 115 | }, 116 | "boundsNoEffects": { 117 | "top": -51, 118 | "left": -104, 119 | "bottom": 1599, 120 | "right": 2312, 121 | "width": 2416, 122 | "height": 1650 123 | }, 124 | "smartObject": { 125 | "placed": "rasterizeContent", 126 | "documentID": "", 127 | "compsList": { 128 | "compID": -1, 129 | "originalCompID": -1 130 | }, 131 | "linked": false, 132 | "fileReference": "Screen Shot 2017-01-13 at 12.52.30 PM.png" 133 | }, 134 | "useAlignedRendering": false, 135 | "generatorSettings": { 136 | 137 | }, 138 | "keyOriginType": [ 139 | 140 | ], 141 | "fillEnabled": false, 142 | "animationProtection": { 143 | "animationUnifyPosition": false, 144 | "animationUnifyEffects": false, 145 | "animationUnifyVisibility": false, 146 | "animationPropagate": true 147 | }, 148 | "artboard": { 149 | "artboardRect": { 150 | "top": 0, 151 | "left": 0, 152 | "bottom": 0, 153 | "right": 0 154 | } 155 | }, 156 | "artboardEnabled": false 157 | } 158 | ``` 159 | 160 | **JSON returned with `extended: true`** 161 | ```javascript 162 | { 163 | "name": { 164 | "stringID": "name", 165 | "charID": "Nm ", 166 | "id": 1315774496, 167 | "key": 0, 168 | "type": "DescValueType.STRINGTYPE", 169 | "value": "Layer 0" 170 | }, 171 | "color": { 172 | "stringID": "color", 173 | "charID": "Clr ", 174 | "id": 1131180576, 175 | "key": 1, 176 | "type": "DescValueType.ENUMERATEDTYPE", 177 | "value": "none", 178 | "enumerationType": "color" 179 | }, 180 | "visible": { 181 | "stringID": "visible", 182 | "charID": "Vsbl", 183 | "id": 1450402412, 184 | "key": 2, 185 | "type": "DescValueType.BOOLEANTYPE", 186 | "value": true 187 | }, 188 | "mode": { 189 | "stringID": "mode", 190 | "charID": "Md ", 191 | "id": 1298407456, 192 | "key": 3, 193 | "type": "DescValueType.ENUMERATEDTYPE", 194 | "value": "normal", 195 | "enumerationType": "blendMode" 196 | }, 197 | "opacity": { 198 | "stringID": "opacity", 199 | "charID": "Opct", 200 | "id": 1332765556, 201 | "key": 4, 202 | "type": "DescValueType.INTEGERTYPE", 203 | "value": 255 204 | }, 205 | "layerID": { 206 | "stringID": "layerID", 207 | "charID": "LyrI", 208 | "id": 1283027529, 209 | "key": 5, 210 | "type": "DescValueType.INTEGERTYPE", 211 | "value": 4 212 | }, 213 | "itemIndex": { 214 | "stringID": "itemIndex", 215 | "charID": "ItmI", 216 | "id": 1232366921, 217 | "key": 6, 218 | "type": "DescValueType.INTEGERTYPE", 219 | "value": 2 220 | }, 221 | "targetChannels": { 222 | "stringID": "targetChannels", 223 | "charID": "", 224 | "id": 3036, 225 | "key": 15, 226 | "type": "DescValueType.LISTTYPE", 227 | "value": { 228 | "count": 3, 229 | "typename": "ActionList" 230 | }, 231 | "list": [ 232 | { 233 | "typename": "ActionReference" 234 | }, 235 | { 236 | "typename": "ActionReference" 237 | }, 238 | { 239 | "typename": "ActionReference" 240 | } 241 | ] 242 | }, 243 | "channelRestrictions": { 244 | "stringID": "channelRestrictions", 245 | "charID": "", 246 | "id": 1196, 247 | "key": 17, 248 | "type": "DescValueType.LISTTYPE", 249 | "value": { 250 | "count": 3, 251 | "typename": "ActionList" 252 | }, 253 | "list": [ 254 | "red", 255 | "grain", 256 | "blue" 257 | ] 258 | }, 259 | "smartObject": { 260 | "stringID": "smartObject", 261 | "charID": "", 262 | "id": 829, 263 | "key": 30, 264 | "type": "DescValueType.OBJECTTYPE", 265 | "value": { 266 | "count": 5, 267 | "typename": "ActionDescriptor" 268 | }, 269 | "object": { 270 | "placed": { 271 | "stringID": "placed", 272 | "charID": "", 273 | "id": 2363, 274 | "key": 0, 275 | "type": "DescValueType.ENUMERATEDTYPE", 276 | "value": "rasterizeContent", 277 | "enumerationType": "placed" 278 | }, 279 | "documentID": { 280 | "stringID": "documentID", 281 | "charID": "DocI", 282 | "id": 1148150601, 283 | "key": 1, 284 | "type": "DescValueType.STRINGTYPE", 285 | "value": "" 286 | }, 287 | "compsList": { 288 | "stringID": "compsList", 289 | "charID": "", 290 | "id": 3017, 291 | "key": 2, 292 | "type": "DescValueType.OBJECTTYPE", 293 | "value": { 294 | "count": 2, 295 | "typename": "ActionDescriptor" 296 | }, 297 | "object": ... 298 | }, 299 | "linked": { 300 | "stringID": "linked", 301 | "charID": "Lnkd", 302 | "id": 1282304868, 303 | "key": 3, 304 | "type": "DescValueType.BOOLEANTYPE", 305 | "value": false 306 | }, 307 | "fileReference": { 308 | "stringID": "fileReference", 309 | "charID": "FilR", 310 | "id": 1181314130, 311 | "key": 4, 312 | "type": "DescValueType.STRINGTYPE", 313 | "value": "Screen Shot 2017-01-13 at 12.52.30 PM.png" 314 | } 315 | } 316 | }, 317 | ... 318 | } 319 | ``` 320 | 321 | ## Example 322 | [descriptor-info-example](https://github.com/JavierAroche/descriptor-info/tree/master/example) 323 | 324 | ## Supported Descriptors 325 | * `DescValueType.BOOLEANTYPE` 326 | * `DescValueType.CLASSTYPE` 327 | * `DescValueType.DOUBLETYPE` 328 | * `DescValueType.ENUMERATEDTYPE` 329 | * `DescValueType.INTEGERTYPE` 330 | * `DescValueType.LISTTYPE` 331 | * `DescValueType.OBJECTTYPE` 332 | * `DescValueType.REFERENCETYPE` 333 | * `DescValueType.STRINGTYPE` 334 | * `DescValueType.UNITDOUBLE` 335 | * `DescValueType.ALIASTYPE` 336 | * `DescValueType.RAWTYPE` 337 | 338 | ## Known Limitations 339 | * `REFERENCETYPE` Descriptors will only return the Descriptor linked, but not it's actual properties. Adding this without properly testing can fall in an endless loop. 340 | * `RAWTYPE` Descriptors, usually labeled `legacyContentData`, will return the value as unicode. You will have to parse it separately as the data varies too much. 341 | 342 | ## Changelog 343 | **v1.1.0 (Dec 08 2017)** 344 | * Added maxRawLimit param 345 | * Added maxXMPLimit param 346 | * Added saveToFile param 347 | * Improved ActionReference / ActionLists 348 | 349 | **v1.0.2 (Jan 13 2017)** 350 | * Added optional params to retrieve extended descriptor information 351 | * Updated example to reflect new optional params 352 | 353 | **v1.0.1 (Jan 3 2017)** 354 | * Added optional params to retrieve reference descriptors 355 | * Updated example to reflect new optional params 356 | 357 | **v1.0.0 (Dec 2 2016)** 358 | * Added descriptor-info JSX 359 | 360 | **v0.0.0 (Dec 2 2016)** 361 | * Initial Commit 362 | 363 | ## License 364 | MIT © Javier Aroche 365 | -------------------------------------------------------------------------------- /example/descriptor-info-example.jsx: -------------------------------------------------------------------------------- 1 | // Include the JSON helper 2 | #include "./helpers/JSON.jsx" 3 | // Include the descriptor-info module 4 | #include "../jsx/descriptor-info.jsx" 5 | 6 | // ActionDescriptor example 7 | var ref = new ActionReference(); 8 | ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 9 | var desc = executeActionGet(ref); 10 | 11 | /** Retrieve its properties by running the getProperties function, passing the ActionDescriptor as a param 12 | * @param {Boolean} reference - return reference descriptors. Could slightly affect speed. Default = false. 13 | * @param {Boolean} extended - returns extended information about the descriptor. Default = false. 14 | * @param {Number} maxRawLimit - limits the max number of characters from a RAWTYPE descriptor. Default = 10000. 15 | * @param {Number} maxXMPLimit - limits the max number of characters from an XMPMetadataAsUTF8 property. Default = 10000. 16 | * @param {String} saveToFile - Saves the descriptor to a JSON file. Default = '~/Desktop/descriptor-info.json'. 17 | */ 18 | var descFlags = { 19 | reference : false, 20 | extended : false, 21 | maxRawLimit : 10000, 22 | maxXMPLimit : 100000, 23 | saveToFile: '~/Desktop/descriptor-info.json' 24 | }; 25 | 26 | var descObject = descriptorInfo.getProperties( desc, descFlags ); 27 | 28 | // Running in ExtendScript 29 | $.writeln(JSON.stringify(descObject, null, 4)); 30 | 31 | // Running in Brackets with the Brackets-to-Photoshop extension 32 | // https://github.com/JavierAroche/brackets-to-photoshop 33 | // Brackets-to-Photoshop extension includes the JSON helper by default 34 | // $.writeln(descObject); 35 | -------------------------------------------------------------------------------- /example/helpers/JSON.jsx: -------------------------------------------------------------------------------- 1 | /** 2 | * JSON - from: https://github.com/douglascrockford/JSON-js 3 | */ 4 | if(typeof JSON!=='object'){JSON={};}(function(){'use strict';function f(n){return n<10?'0'+n:n;}function this_value(){return this.valueOf();}if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+f(this.getUTCMonth()+1)+'-'+f(this.getUTCDate())+'T'+f(this.getUTCHours())+':'+f(this.getUTCMinutes())+':'+f(this.getUTCSeconds())+'Z':null;};Boolean.prototype.toJSON=this_value;Number.prototype.toJSON=this_value;String.prototype.toJSON=this_value;}var cx,escapable,gap,indent,meta,rep;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)).slice(-4);})+'"':'"'+string+'"';}function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key);}if(typeof rep==='function'){value=rep.call(holder,key,value);}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(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i