Repair toSource() for enumeration values

Since CS5 InDesign uses enumerator objects for enumeration values.

This script replaces the toSource() method of those enumerators so that they return something better than the default "({})".

Usage

// DESCRIPTION: Display a dialog with some enumerations. #target "InDesign" #include "/www.ixta.com/scripts/utilities/enumToSource.jsx" var what = "app.anchoredObjectSettings"; alert(what+"\n"+eval(what).properties.toSource() .replace(/, /g,",\n").replace(/:/g,": "));

The Script

// DESCRIPTION: repair toSource() for enumerations. // http://www.ixta.com/scripts/utilities/enumToSource.html // // Copyright 2014 Dirk Becker, all rights reserved. // This program may be used freely for development purposes. // Redistribution without written permission is prohibited. with( NothingEnum.NOTHING.constructor.prototype ) { toSource = function () { return callee.map[this.valueOf()] || "({})"; }; ( function () { var map = this.map = {}; var classes = $.dictionary.getClasses(); // ["Assignment", "Assignments", while( classes.length ) { var classname = classes.shift(); var classdef = $.dictionary.getClass(classname).toXML(); if( classdef.@enumeration=="true" ) { var properties = classdef.elements.property; for( var inx=0, cnt=properties.length(); inx<cnt; inx++ ) { var property = properties.child(inx); var key = String(property.@name); var val = Number(property.datatype.value); map[val] = !map.hasOwnProperty(val) ? classname + "." + key // first definition : val + " /* " + key + " */"; // redefinition } // each enumerator value } // if is enumeration } // each classname } ).apply(toSource); }