lgging

Post Reply
mmusger
Newbie
Posts: 6
Joined: Thu Apr 28, 2011 11:43 am

lgging

Post 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?


freddyp
Advanced member
Posts: 413
Joined: Thu Feb 09, 2012 3:53 pm

lgging

Post 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
mmusger
Newbie
Posts: 6
Joined: Thu Apr 28, 2011 11:43 am

lgging

Post 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.
freddyp
Advanced member
Posts: 413
Joined: Thu Feb 09, 2012 3:53 pm

lgging

Post 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
mmusger
Newbie
Posts: 6
Joined: Thu Apr 28, 2011 11:43 am

lgging

Post by mmusger »

Thanks for the solution. Works like a charm.
Post Reply