Add highly customized Text Variables to InDesign

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 !

Download AddCustomVariables

9 responses on “Add highly customized Text Variables to InDesign

  1. Tia says:

    This script is wonderful! I coordinate a large project with 8 designers who each contribute different ads, and sometimes they forget to mark who designed what ad. This script marks them automatically now and it’s exactly what I was looking for.


  2. Glad we could help you in your design workflow 😉

  3. How can I get XML tags and possibly the elements attributes to be variables? I want node ids and other XML data to be conditionally visible in the layout.


    • Steven Six says:

      Hi Daniel,

      Did you yet found the solution. I’m searching for exact the same feature.

      Please advise

      • Hi guys,

        You can pass a function resut as the “contents” parameter. So given you want some xml node contents, you may use thus assuming the tag is valid :

        createTextVariable(doc, “my xml node”, getXMLNode(doc) );

        where getXMLNode(doc) is set as :

        function getXMLNode(doc) {

        //the root xml node of the document
        var root = doc.xmlElements[0];

        //The xml node array retrieved by XPath expression evaluation against the root node.
        //=> //myNode looks for any myNode nodes at any place.
        var myNode = root.evaluateXPathExpression ( “//myNode” );

        //the contents to return;
        var contents = “”;
        myNode.length && contents = myNode[0].xmlContent.contents;

        return contents;


        That should do the trick.

  4. Trevor says:

    Hi loic,

    Thought the following might make you smile

    var isMac = $.os[0] == “M”;
    var userName = $.getenv(isMac ? “USER” : “username”);
    var computerName = isMac ? app.doScript(“get computer name of (system info)”, ScriptLanguage.APPLESCRIPT_LANGUAGE) : $.getenv(“computername”);
    alert (“Computer Name: ” + computerName + “\rUser Name: ” + userName);


  5. Thanks a lot Trevor,

    Hope that helps someone 🙂


  6. Jennifer says:

    Do you know if it is possible to have a text variable show the number of pages left in a section similar to how iBooks shows page numbering?

  7. This is EXACTLY what I was looking for, but I’m not confident I can customize it. Could you help me insert a custom text variable that is the FONT being used in the current text block? This is for a style-based FONT sample sheet.

Leave a Reply

Your email address will not be published. Required fields are marked *