August 3rd, 2009
If you are an InDesign scripter, you may find this interesting.
When I create scripted extensions, I always break things up into files that make things manageable. A large project for me might contain 200 script files. Rather than try to stuff it all into a single script for delivery, I came up with a template that I use for just about all my InDesign scripting projects that makes this about as easy as it can be. This concept really only applies when a script will reside in a persistent (named) scripting engine and adds menus to the InDesign menu bar and/or context menu.
I have made the template available in the Free Stuff page of this site, so go ahead and download it.
When you unzip it, it creates a folder. Inside that folder is “startup scripts” that contains one jsx, “loader.jsx”. That file loads the entire extension. It recursively looks through all the folders and loads the entire project into the named scripting engine for you.
There’s a “resources” folder. It contains things, like images, that are not jsx files. The loader script does not load anything in the resources folder. As another freebie, I put some ESTK extensions in this folder. There’s a PDF that describes how to install and use them. One of those extensions does a batch conversion to jsxbin. It places all of the scripts into a “bin” folder except those in the “startup scripts” and “jsx” folder. The loader script that creates the names engine can not be a jsxbin. Files in the jsx folder are those script files which should not be converted to jsxbin (basically any class definition that might be serialized and deserialized using toSource()).
When you convert a project to binary for delivery, the loader script contains a flag, “loadBinary”. If you set that flag to “true”, it will load the binary files. You then remove the jsx’s to hide your source code, and yer’ done.
Just to be clear – use the tempate (it has examples of menu creation, context menu creation, and some handy libraries), complete and test the project, convert it to binary (one step), remove the jsx files (other than those in the jsx folder), set the loader’s loadBinary to “true”, and you are ready to ship projects that are arbitrarily huge.