0

I'm writing some scripts in ActionScript to automate some tasks in Adobe Indesign 2019 (part of the Creative Cloud Suite), but this applies to all scripting for all applications in Adobe Creative Cloud.

I don't want to use ExtendScript Toolkit for editing/running the script, because it is terribly slow.

Because there is no such thing as console.log() available (at least that I'm aware of) and alert() will stop for user input to continue, I created a small file logger, but it does not append the file, but keeps on overwriting the first line. I use tail -f indesign.log to monitor the log file.

Here is the code of the logger

function logger(message){
  var logFilePath =  new File ('indesign.log');
  logFilePath.encoding = 'UTF-8';
  try {
    logFilePath.open('a');
       }
  catch(err) {
              logFilePath.close();
              logFilePath.open('a');
             }
    logFilePath.write(new Date().toLocaleString() +": "  +   message + "\n");
    //logFilePath.writeln(new Date().toLocaleString() +": "  +   message + "\n");
    logFilePath.close()
        }

logger("Script started")
logger("2nd line")
logger("3rd line")
logger("4th line")
logger("Script finished")

I tried also using writeln instead of write, but it does not make a difference.

I tried different line feeds, like "\n" and "\r\n", but it does not make a difference.

I tried different File.open options like .open('w'), .open('ra'). The documentation about this is either not clear or really outdated (Or I just can't find it).

Any suggestions in the comments about the best IDE to edit/run ActionScripts is highly appreciated.

Paul Verschoor
  • 1,479
  • 1
  • 14
  • 27
  • This works absolutely fine for me. Ran it through ESTK and from InDesign script panel. It adds a new line every time you run it. Tested with CS5.5 – Nicolai Kant Feb 06 '19 at 12:38
  • @NicolaiKant If you log some more lines, will it append to the file? The first line is always overwritten when I execute the code. – Paul Verschoor Feb 06 '19 at 15:47
  • Wednesday, February 06 2019 23:55:27: Script started Wednesday, February 06 2019 23:55:27: 2nd line Wednesday, February 06 2019 23:55:27: 3rd line Wednesday, February 06 2019 23:55:27: 4th line Wednesday, February 06 2019 23:55:27: Script finished – Nicolai Kant Feb 06 '19 at 23:56
  • The output I am getting. The comment removes the CRs – Nicolai Kant Feb 06 '19 at 23:57
  • I run a copy of your script, did not change anything apart from pointing the file path for the log file to the desktop – Nicolai Kant Feb 06 '19 at 23:58
  • When I open the file in a texteditor (Atom), it’s all on one line. I’m on macOs btw. – Paul Verschoor Feb 07 '19 at 00:03
  • So did I. Atom, Mac OSX. I do have lines separated for every entry – Nicolai Kant Feb 08 '19 at 14:01
  • You can try to add line explicitly logger("Script started\n"), although on mine I will get double new line – Nicolai Kant Feb 08 '19 at 14:03

0 Answers0