Reputation: 2679
I'm doing a bit of Photoshop scripting for the first time and it sure would be great to have a console.log-like function to output array and object values in the Javascript console of the ExtendScript Toolkit App.
Is there an equivalent function?
Upvotes: 48
Views: 37937
Reputation: 4506
$.writeln()
is what you're looking for. See the JavaScript Tools Guide (PDF) for details.
Upvotes: 71
Reputation: 2446
I know this is old, but I was recently in need of logging for some values of an InDesign script and I'd like to share my "solution".
My first problem was that I didn't even figure out where the output produced by $.writeln()
goes. So I resorted to a crude function that logs to a file in the document directory. Maybe it'll be of use to somebody. I'm guessing this may work for Photoshop or other ExtendScript environments as well.
I learned that ExtendScript does not support JSON
methods, so I used a polyfill. Simply put the file (in my case json2.js
) in the same directory as your .jsx
.
#include "json2.js"; // include polyfill file
function log (input) {
if(!debug) return;
if(!JSON || !JSON.stringify) return;
var now = new Date();
var output = JSON.stringify(input);
$.writeln(now.toTimeString() + ": " + output);
var logFile = File(app.activeDocument.filePath + "/log.txt");
logFile.open("a");
logFile.writeln(now.toTimeString() + ": " + output);
logFile.close();
}
var debug = true;
log("abc 123");
log([1, 3, 4343, "ddddd", null, false]);
Use the debug
variable to quickly enable or disable output.
Upvotes: 2
Reputation: 59
I'm using ExtendScript Toolkit version 4.0, and using _print('foo')
seems to do the trick.
Upvotes: 4
Reputation: 12903
write("any message");
Is what works in XTools for Photoshop. I find that the Photoshop debugger crashes all the time in CS6 on Mac OSX.
You can find more about XTools here: http://ps-scripts.sourceforge.net/xtools.html.
It's fabulous!
Upvotes: 1