Skip to content
Fabian Morón Zirfas edited this page Jun 13, 2025 · 4 revisions

Properties

/*
You can inspect objects by using
toSource()
and
toString()
*/
var o = {
	a: "Hello World",
	b: 5.5,
	c: true,
	x: [1, 2, 3],
}; //Object

alert(o.toSource());
alert(o.toString());

If you want to output something into the Console of the ESTK use $.writeln()

$.writeln("Hello World");// use this in ESTK

Properties

Every object has lots of and different properties. You can look for them in the references mentioned in the first session. Also you can inspect them directly with the Example script inspectProperties.jsx.

main();

/*
	Main Function everything is in here
*/
function main() {
	// store the reference to an object in a variable
	//~ var ref = app.activeDocument.paragraphStyles.item(1);
	// var ref = app.activeDocument.pages.item(0);
	var ref = app.fonts.item(0);
	// you could also use the selection
	// if(app.selection.length > 0){
	// var obj = app.selection[0];
	// };
	var insepction_result = inspectObjectProps(ref);
	var res = null;
	res = confirm("Write output to file?", false, "Title WIN only");
	if (res == true) {
		writeArray(insepction_result, ref);
	} else if (res == false) {
		alert("Properties of " + String(ref) + "\n" + insepction_result.join("\n"));
	}
}

/**
 *  This inspects the object by looping it and
 *  turning the result to an string
 *
 */

function inspectObjectProps(obj) {
	var arr = new Array();
	for (var key in obj.properties) {
		arr.push("'" + key + "':" + obj[key]);
	}
	return arr;
}

function writeArray(arr, obj) {
	//select an output folder
	var newLocation = Folder.selectDialog("Select a output folder...");
	// give the file a unique name
	var timestamp = Number(new Date());
	// now build the filename. fn you get it?
	var fn = "file " + timestamp + String(obj);
	// now set the output folder
	// fs means file system
	// tf means target folder
	var tf = newLocation.fsName;
	// add the new file under the location to the file system
	var txtFile = new File(tf + "/" + fn + ".txt");

	var out;
	if (txtFile != "") {
		//Open the file for writing.
		out = txtFile.open("e", undefined, undefined);
		txtFile.encoding = "UTF-8";
		txtFile.lineFeed = "Unix"; //convert to UNIX lineFeed
		// txtFile.lineFeed = "Windows";
		// txtFile.lineFeed = "Macintosh";
	}
	if (out != false) {
		for (var i in arr) {
			txtFile.writeln(arr[i]);
		}

		txtFile.close();
		txtFile.execute();
	}
}

Home

Clone this wiki locally