2 Replies Latest reply on Apr 29, 2008 4:42 AM by (hp_)

    [CSX] [JS] Where am I?

      hi all,

      i just checked the possibilities of ui scripting and i'm quite amazed what is possible without big fuzz...

      but i can't realize how i can find the insertion point or current position in an open document from my script. i just think about sth like a user interface to with some buttons und text which will create a table or textblock at the current insertion point.

      i guess i'm blind, but i can't find a way to find the current position in within the document ?!?

      the scripting guide does only provide examples how to create new documents or textframes what isn't what i want to do.

      any ideas?

      thanks a lot,
        • 1. Re: [CSX] [JS] Where am I?
          Level 1
          Pieces of information missing from your message:

          Version of InDesign.
          Scripting language of choice.

          The current selection, in any version of InDesign in JavaScript can be addressed by:


          This is an array of all selected objects. If the selection is text, then it is an array of one object. When I'm writing a script that works on the current text selection, I always use this framework to kick things off:
          if (app.documents.length > 0 &&
                  app.selection.length == 1 &&
                      app.selection[0].hasOwnProperty("baseline")) {

          function processSelection(myText) {

          First, you have to make sure there is a document open, otherwise the attempt to address one of its members will fail. Then, for it to be text, there must be only one item selected, finally, if the selection is text, then it will have a baseline property that no other object has. So, if I get that far, I know that the selection is text (although it might yet be just an insertion point), and I can process it. Usually, I change the name of the "processSelection" function to match the actual purpose of the script.

          • 2. Re: [CSX] [JS] Where am I?
            Level 1
            sorry for the missing information. i edited my post - but to late anyway.

            your code is working fine! thanks a lot.