home
NOTE: Under Construction - I'm in the middle of upgrading my site and lots of stuff is kinda broken. Please forgive the mess.

ps- js- Basic write to file.txt

March 2014

NOTE: These don't seem to not be working consistently in photoshop cc 2022. Need to investigate more, but don't count on it at this poing

Code
const logFile = new File('~/Desktop/adobe-script-file.txt')

function log(msg) {
  // TODO: Move this into a try catch
  if (logFile.open('a', 'TEXT', '????')) {
    logFile.writeln(msg)
    logFile.close()
  }
}

log('Hello, world')

#+OLDNOTES:

Make sure to set the lineFeed property.

Code
var tFile = new File('~/Desktop/missing-dir/ExtendScript-test.txt');
if (tFile.lineFeed === 'macintosh') {
    tFile.lineFeed = "unix";
}
if(tFile.open('a', 'TEXT', '????')) {
    tFile.writeln("asdf");
    tFile.close();
}
else {
    $.writeln("Could not open file: " + tFile.absoluteURI);
}

This $.writeln() stuff used to go to ExtendScript toolkit, but that's been dead for a while now.

═══ § ═══