InDesign text variables are really powerful. I recently saw a forum post where some people was asking if it was possible to add the computer name to the InDesign text variables. At first, I was about to answer him “no, you can’t”. And the fact is you normally can’t…Unless you get some InDesign Scripting in the loop 😉
So I wrote this snippet that will add two more text variables to InDesign, the user name and the computer name. It’s quite open so one may tweak it for it’s own need. The only “tough” part was to get the valuable information such as the user name and the computer name. It was solved by a simple navigation inside the Folder class. Finally the user name was accessible through :
And the computer name here :
I have then released a first version that revealed a few hiccups. As David Buxton pointed out in his comment, what I thought was the computer name was indeed, the Hard Drive name. So I won’t get “John’s computer” as a name but maybe “Toshiba 123XDF” which was quite pointless in a production environment. Ok, I knew I have to talk a bit deeper to the system but the ExtendScript DOM can’t allow you to go that far. I needed to use more dedicated languages but OS specific though. In clear english, I had to use both Applescript and VisualBasic to make the script still compliant on both OS. Applescript was fine for me, not VisualBasic.
Thanks to Jimmy Hartington, I have been given a link to some VBS snippets and Marijan Tompa (aka tomaxxi) offered his hand to make the vbs snippet running perfectly. In the end, I had my two OS specific snippets at hand. Fortunately, InDesign proposes a bridge to os specific code execution through the doScript method. That was it, I was then able to get the true computer name.
Last but not least, Stephane Bosso who used the script noticed that although the text variables did appear in InDesign, they weren’t updated. Indeed, once added, the text variables kept their content through all the computers the files were open on. So I had to implement an updating mechanism in order to get this dynamic control of the system text variable. Now, it’s really working as expected or I hope so :).
To get the script running effectively, you need to place it into the startup scripts folder. That way, the extra variables will always be accessible.
See a demo of AddCustomVariables Script
Go frenzy with variables !