Skip to main content
March 8, 2013
Answered

Is there a way with JSX to save text to a file?

  • March 8, 2013
  • 2 replies
  • 6196 views

I'm looking for a way to save JSX script-generated log entries to a text file, not just from Photoshop but also from InDesign and Illustrator as well. There are discussions elsewhere about using the DataObject class, but those discussions are from a few years ago, there is nothing about them (that I could find) in the CS6 documentation, and nothing comes up in EST's auto-complete. Any ideas? Thanks

This topic has been closed for replies.
Correct answer Paul Riggott

Something like this?

logInfo((new Date).toString());
logInfo("This is the first message");

logInfo("This is the second message");

function logInfo(Txt){
var file = new File(Folder.desktop + "/ScriptLog.txt");
file.open("e", "TEXT", "????");
file.seek(0,2);
$.os.search(/windows/i)  != -1 ? file.lineFeed = 'windows'  : file.lineFeed = 'macintosh';
file.writeln(Txt);
file.close();
};

2 replies

Inspiring
January 22, 2019

excellent, thank you Kukurykus!!

Paul Riggott
Paul RiggottCorrect answer
Inspiring
March 8, 2013

Something like this?

logInfo((new Date).toString());
logInfo("This is the first message");

logInfo("This is the second message");

function logInfo(Txt){
var file = new File(Folder.desktop + "/ScriptLog.txt");
file.open("e", "TEXT", "????");
file.seek(0,2);
$.os.search(/windows/i)  != -1 ? file.lineFeed = 'windows'  : file.lineFeed = 'macintosh';
file.writeln(Txt);
file.close();
};

March 8, 2013

That would do it. Thanks so much. Out of curiosity, is that anywhere in Adobe docucmentation or is this pure Javascript?

Paul Riggott
Inspiring
March 8, 2013

You can find this information in the Object Model Viewer under Help in ExtendScript Toolkit

Look at Core JavaScript Classes and select File

Hope it helps.