Page 1 of 1

lgging

Posted: Tue Oct 08, 2013 5:40 pm
by mmusger
Hi,



I was creating a script for Indesign and I was wondering how you could log some things to the message pane in Powerswitch.



Logging errors is done like:





catch(theError) {

$error = theError.description;

}





Many scripting mistakes does go to the catch method but it only states: %1. That is not a lot of help.

So I tried:





catch(theError) {

if (theError.description == "%1") //also tried $error == "%1"

$error = "test error message";

else

$error = theError.description;

}





But that doesn't work,

I would like some normal logging (or warnings or debug messages, they are easier to read)

In Switchscripter it's easy (s.log(1,"test warning");)

How do I go about that in a command execution script for an Adobe app?



lgging

Posted: Wed Oct 09, 2013 11:29 am
by freddyp
You cannot log anything to the Switch environment as long as you are in the Indesign environment. Indesign does not write to standard output, so there is no way to catch any messages coming out of Indesign. All Switch can know about is the exit status and any error messages.



If you need the messages for debugging your script, use alert("your very own message");. This will pop up a dialog box in Indesign and you can let it display anything you want from within the Indesign context. Of course, this is only useful during the writing of the script; do not use this in production as it halts Indesign until you click on the OK button.



If you really must have messages about what your script has been doing inside Indesign, write your messages into a text file, add the text file to the $outfiles array and after the Indesign configurator you divert text files to a script in which you read the lines and log them.



Freddy

lgging

Posted: Thu Oct 10, 2013 2:38 pm
by mmusger
Thank you for your insight.

I thought it wasn't possible but didn't think of the extra txt file.



Well, I gave it a try



function schrijfTXT(tekst){

var a = new File($outfolder+"_error.txt");

a.open('w');

a.writeln(tekst);

a.close();

$outfiles.push(a);

}



The txt is created and filled with correct data but it results in an error in the log of Powerswitch:



Failed to place job '_0TOZ2_Untitled_paginastemp_error.txt' in folder 'Folder 2'


Where 'Folder 2' is a normal outputfolder connected to the Indesign configurator.

lgging

Posted: Fri Oct 11, 2013 1:56 pm
by freddyp
The $outfiles array contains strings with the path of the output files created by your script. However, the variable a is a File object. Push a.fsName and all will be well.



Freddy

lgging

Posted: Fri Oct 11, 2013 3:33 pm
by mmusger
Thanks for the solution. Works like a charm.