48

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?

Alan W. Smith
  • 24,647
  • 4
  • 70
  • 96
Sebastien
  • 2,607
  • 9
  • 30
  • 40

4 Answers4

71

$.writeln() is what you're looking for. See the JavaScript Tools Guide (PDF) for details.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Daniel Serodio
  • 4,229
  • 5
  • 37
  • 33
  • This does not work using the xtools extension for Photoshop CS6. – justingordon Oct 13 '13 at 22:16
  • Doesn't output anything on Adobe Extend Script 4! – numediaweb Jun 20 '14 at 15:38
  • Just tried in ExtendScript CS6 and works beautifully. – David van Driessche Nov 18 '15 at 14:34
  • 3
    Although this outputs to the console, there is no information either here or in the link posted where this console is (I didn't see it in the vsc console), which makes this post unhelpful for some people. Also, the docs provided in the link are from 2010, and are therefore unreliable. I think it's time for a more updated answer to this question. – John Miller Jun 27 '21 at 17:55
  • This works perfectly in ExtendScript 4.2.12. For those who do not know, the console is a window in the extendscript tool. Which is exactly what the OP asked about. – Joe Johnston Jan 07 '23 at 17:32
4

I'm using ExtendScript Toolkit version 4.0, and using _print('foo') seems to do the trick.

Cas
  • 59
  • 2
2

Log to a file instead

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();
}

Usage

var debug = true;

log("abc 123");
log([1, 3, 4343, "ddddd", null, false]);

Use the debug variable to quickly enable or disable output.

oelna
  • 2,210
  • 3
  • 22
  • 40
1
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!

justingordon
  • 12,553
  • 12
  • 72
  • 116