Please Help! Trying to attach Javascript to InDesign Command.

Post Reply
JohnPCS
Newbie
Posts: 10
Joined: Thu Sep 15, 2011 9:46 pm

Please Help! Trying to attach Javascript to InDesign Command.

Post by JohnPCS »

I'm not having much luck with getting Switch to run a script in InDesign. I really hope someone can point me in the right direction, because I'm just going in circles at this point!



My workflow:

Hotfolder -> InDesign (Command: Script) -> Processed Folder



My configuration for InDesign is simply to run a script using the Command option - I'm not running any scripts for Open or Save As.



The error I get in the log file is this:

Script returned error:



That's it. Blank. I can't figure out what the problem is!



1. //Get document name and document ID

2. var myDocument = $doc;

3. //var myDocument = app.activeDocument;
One of the first things I found was to use $doc instead of activeDocument. When I comment out line 2 and use line 3,the script runs perfectly when launched in InDesign manually. So I *think* my script is sound. I can't help but feel I'm doing the $doc part wrong somehow...



I tried adding $doc as one of the Arguments in Switch, but that did not seem to help at all.



Essentially, my script looks at the file name to determine which PDF Preset to use and where to place the PDF (IF-THEN).



How do I debug this script in Switch if all I get is blank error messages? Can someone please help me out?



Thank you!
Evan
Member
Posts: 30
Joined: Mon Feb 28, 2011 6:44 pm

Please Help! Trying to attach Javascript to InDesign Command.

Post by Evan »

I don't know a lot about InDesign scripts but I have work with Acrobat and It seems similar.



The way I work is I put a script at application level into a function and I only call the function so the only text in my command line is:



ToPrinergyRefine()



Or you can call a menu item like:



app.execMenuItem("To Prinergy Refine")



If you want to pass an argument to acrobat, or InDesign in your case, you can to use the following variable:

$arg1

$arg2

$arg3

$arg4

$arg5

$doc



The reason why you don't have any error message is probably because you have to set $error to an error message so Powerswith is able to get it. The following script might help you:





/*=======================================

// This script can be used to fill out the following document information fields:

* $arg1 = Title

* $arg2 = Author

* $arg3 = Subject

* $arg4 = Keywords

* $arg5 = Creator

It is possible to enter a fixed text string or to add a variable using a script expression.



----------------------------------------------------------------

Author: Kristof Kemseke, Gradual Software

Last changed: November 6, 2006

Copyright: (c) 2006, Gradual Software

========================================

*/



if($error == null)

{

try

{

if (($arg1 != null) && ($arg1 != ""))

$doc.info.Title = $arg1;



if (($arg2 != null) && ($arg2 != ""))

$doc.info.Author = $arg2;



if (($arg3 != null) && ($arg3 != ""))

$doc.info.Subject = $arg3;



if (($arg4 != null) && ($arg4 != ""))

$doc.info.Keywords = $arg4;



if (($arg5 != null) && ($arg5 != ""))

$doc.getField("interieur").value = $arg5;

}

catch(theError)

{

$error = theError;

$doc.closeDoc( {bNoSave : true} );

}

}



--

Evan


JohnPCS
Newbie
Posts: 10
Joined: Thu Sep 15, 2011 9:46 pm

Please Help! Trying to attach Javascript to InDesign Command.

Post by JohnPCS »

Thanks for the reply Evan!



I figured the most important thing was getting the error to show up, so I've added the Try-Catch routine around my script but I am still getting the same blank error message in the log.



I'll also look into how to convert the script to an Application level function, but I really really wish I could see what the script is actually breaking on!



I also went through and instead of trying to assign $doc to a variable, explicitly stating $doc everywhere that I previously had the myDocument variable. Didn't help.



If you have any other thoughts on how to make the log give useful information on the error in the script, please let me know!



Thanks
Evan
Member
Posts: 30
Joined: Mon Feb 28, 2011 6:44 pm

Please Help! Trying to attach Javascript to InDesign Command.

Post by Evan »

Actually I never try to make appear error messages. The way I use is a kind of workaround. Because I use a simple script to call another script it might be hard to have logs.



To convert your script to an application level function you have to create a text file following this:



fonction TheNameOfTheFonction () {

Paste your script here and use "$doc" variable

}



Then save it to your InDesign Application Folder into Script/startup scripts and add the extension ".js". Restart InDesign.



Now you need only to call your function to make it work.



Create another text file and write only:



TheNameOfTheFonction ()



Save this text file and link Powerswitch to it.



Good luck!


JohnPCS
Newbie
Posts: 10
Joined: Thu Sep 15, 2011 9:46 pm

Please Help! Trying to attach Javascript to InDesign Command.

Post by JohnPCS »

Thanks again, Evan! I will give that a try later today.



An interesting aside: I got the blank scripting error message on a Flow that had previously been working fine. It was unchanged and after a server reboot I got the error. The really interesting part is that the Configurator wasn't set to launch a custom script - just to Save As using a certain PDF Preset.



All I had to do was quit InDesign and try again and the flow worked fine.



Does anyone have any experience with the InDesign configurator? It does not seem reliable. Not sure what I'm doing wrong, if anything. Reliability is a top concern for me, obviously!



Thanks
Post Reply