I can't provide working steps, as I haven't had the urge to start up Windows in years.
The InDesign Scripting Tutorial also has some steps, search for TLB in
Dim ws As New IWshRuntimeLibrary.WshShell ws.Run ("C:\Users\carlos\Documents\Adobe Scripts\yourScript.jsx") 'change to your own path
the only issue is, it does not seem to allow spaces...so you have to move your script to another folder where you'll get the security warning.
Thank you CarlosCanto.
Following the script above incl adding the Reference to WSH the VBA script is successfully launching InDesign and starting the script.
However, InDesign is hanging (when it appears opens an Indd template file). I sense I need to add something in either the VB script or Indd script or both to .....
a. from an Indd perspective.... return control to the VB script
b. from a vba perspective ... understand when the Indd actions are complete and end the script.
When I run the script from my desktop (where I have the script file with no spaces in the name) the Indd script works perfectly.
I am so tantalisingly close to the final solution.......
I am following a lead to the hanging behaviour.
My jsx script is creating one Indd file and also exporting a low and hi-quality pdf file (3 file outputs in total). These are stored in a particular folder. When I run the Indd script from my desktop (ie double click on the jsx file) the script will happily overwrite the existing files (which is what I want).
If I have the script executed from the VBA script it will work perfectly when there are no files to overwrite but hangs if it needs to overwrite the files. I will probably have to get the Indd script to recognise if the files exist, if so delete them ( I assume this is possible within Indd script).
Nearly nearly there.
I would still welcome any comments on this posting or post no.6.
Thanks to all for your help.
Unfortunately, post 7 above is not the answer. When I ran the scripts again (with no files to overwrite) it hung in the same place.
The Jsx script is actually working to an extent. It is opening a template and actually starting a datamerge. It appears to open the first page of the new data merge document, but not populate any of the merge fields.
Any ideas how I can stop the jsx script so I can debug it from a known working location.
I have $.bp() statements at critical places in the script (maybe that's the problem).
Is there a statement I can use to halt the jsx script so I can debug from a certain point when running the script from vba thru the WshShell approach.
Word exhibits a curious behavior when I run a VBA script in it that targets InDesign. While it is running, *I can still work with InDesign*! It seems VBA (or likely *any* external script) is running asynchronously. I expect Excel to do the same ...
If you sandwich your script commands between InDesign and Excel, you might find this to be the cause of hangs and other unexpected behavior. For instance, Excel starts a native InDesign script that ought to create a new document. Now before InDesign is ready, the Excel script continues with its next command -- attempting to copy text into this -- not yet existing! -- new file.
You'll have to experiment with what you do in each of the scripts. In my scenario above, you might be able to solve it by having the Excel script create the ID document, for example.
I suspected all along that Excel is running ahead of itself.
So, I can step thru the Excel vba script and get it to execute the command to execute the Jsx script.
I can then see InDesign launch, open the primary Indd template, start the data merge, create the first page of the datamerge output and then stop. I still have not gone onto the next VBA instruction.
I am going to explore my code for any statements which either post info to the Indd console or $.bp() type (which work fine when running the jsx script from the desktop, but may cause different behaviour when run from a different master than the Indd ExtendScript Toolkit ).
I will definitely need to add something to the vba script to pause it until it gets an instruction that the Indd script has finished (another little project).
[Ps. I thought the challenge was to get my jsx script to do all the things I needed with my documents and images. I figured that calling this from a vba script would be a simple single line instruction and a piece of cake. I am really really happy with my jsx script in terms of its primary function, but need it to execute from VBA to achieve the workflow benefits. One lives and sometimes learns.]
So.. are there any commands in jsx I can use to halt it in debug mode,, when not inside the Extendscript Toolkit.
I found the final critical problem. As usual "doh".
- I am in Lightroom, have completed my edits to a bunch of images, finalised all my metadata (Titles, captions, locations, etc).
- I use ListView PlugIn to generate a list of all the images I want to create Indd or PDF formatted documents for.
- Click Export to Excel ( a critical/ fantastic feature of Listview...watch out for issues with CSV...use HTML option).
- My list of images and related metadata opens in Excel. I have my Excel macro on a command button. Click.
- InDesign launches, progresses and hangs at the data merge stage.
Solution. Modify the XL script to close my current workbook.
My jsx script now works, regardless of whether I have previous copies of the output files there or not (ie will overwrite if the are present. This is what I want, as the folder will always have the lates results of this script.
So, I am now a very happy bunny, and grateful for all the input. Every single response opened up options for me to progress.
I still have an edgy feeling that the VBA script should be waiting for the JSX action to finish and then exit smoothly. I will explore how that can be achieved.
Also, the script leaves Indesign open (with all files closed....as per jsx script). I want to figure out how to close InDesign remotely and smoothly.
This will leave me back in Lightroom, looking at my list of images within the ListView Plug-in....and all my document professionaly packaged in pdf and Indd products.
I have been really impressed with the contributions from the InDesign scripting community. I include in this John Beardsworth , who responded very quickly to an issue within his plug-in (List View).