GREP to Anchored Object

Using “GREP to Anchored Object”


Grep to Anchored Object is a useful InDesign script that makes it easy to extract any text in your document out of the main flow of the text and into an anchored object. The anchored object will be anchored to the original location of the text.

What are anchored objects?

An anchored object is any page item (such as a graphic, or, in our case, a text frame) that is linked (or “anchored”) to text. If the text moves, the anchored object travels with it.

Anchored objects have many settings, mainly relating to where on the page the anchored object should appear. They can flow directly with the text, or always appear on a fixed point on the page relative to the text, and much more.

It is beyond the scope of this guide to explain in detail all the options available for anchored objects – more information about them is available here:

Before running the script

Two preparatory steps are required before running Grep to Anchored Object:

  1. Create a GREP query that will find the text you wish to extract and place in the anchored object.
  2. Create an object style for the anchored objects the script creates.

These steps will be described below.

STEP 1: Creating a GREP query

  1. Open InDesign’s Find/Change dialog and click on the GREP tab:

  1. Set up your GREP query as you like: You can search for specific text, or just a paragraph or character style, or any text with special formatting, and so on. The possibilities are endless.
  2. GREP to Anchored Object optionally can be set to perform a “Change GREP” on the text it extracts and places into the anchored objects. If you would like to use this option, set up the “Change to:” options as needed.

STEP 2: Creating an object style

If you have not already done so, create an object style that the script will use for the anchored objects it created.

Using the object style’s “Anchored Object Options” set the position and style of the anchored object you wish to create.

You are now ready to run the script.

GREP to Anchored Object settings

Here’s a screenshot of the GREP to Anchored Object window:

Grep to Anchored Object Options Screen


  1. Anchored object style: This dropdown menu will list all the object styles in the current document. Select the object style to use for the anchored objects that will be created. The way the selected object style is set up will make a big difference to the way the pages will look after the anchored objects are created. But of course, you can always change the object settings after running the script as well!
  2. Width: Type in the preferred width you would like each anchored object to be given. This is not something that can be set easily as part of an object style. The desired width must be entered in millimetres only.
  3. GREP options: GREP to Anchored Object will extract your text and place it in an anchored object. If you select this option, it will then perform a “change GREP” operation (based on InDesign’s current “change GREP” settings) on the text inside the anchored object it has created.
  4. Location options: By default, the objects created by the script will be anchored to the exact same place as the original text. However, two additional options allow you to link the object to the end of the previous paragraph (the paragraph before the paragraph in which the found text is), or to the start of the paragraph in which the found text is.
  5. Scope: Here you can select whether the script should extract text only from the current selection, the current story, or from the entire document. To use the “Current selection” option, select some text before running the script. To use the “Current story” option, select some text or a text frame before running the script.
  6. OK Button: Click OK to run the script based on the settings chosen. All text found (based on InDesign’s current “find GREP” settings) will be extracted from the main text flow and placed into an anchored object to which will be applied the selected object style. If selected, a “change GREP” operation will also be performed on the text in each of the newly created anchored objects.
  7. Cancel button: Close the window and exit without doing anything.
  8. About button: Opens a new window which shows the current script version, provides an option to add this script to the optional Id-Extras menu, and also includes links to this page, the EULA, and the products page.

All settings you make are stored with the document for convenience so they needn’t be reentered every time the script is run. Also, even if you need to edit the document several months later and re-run the script, the old settings should still be there. (This does not affect document portability – so someone who does not have GREP to Anchored Object will still be able to open and edit the document without seeing a “missing plug-in” alert!)

Questions? Comments?

Please feel free to write your questions or comments about Grep to Anchored Object below.

Article Comments

  1. Raphael

    February 27, 2024 9:21 am Reply

    ooh yes, searching for colour is brilliant. Thank you!

  2. Raphael Freeman

    February 26, 2024 4:50 pm Reply

    If I have 4 paragraphs of different styles that I want to put into an anchored box, is this possible with Grep?

    • Ariel

      February 27, 2024 2:42 am Reply

      Hi Raphael,
      I’m not sure what you mean. If you mean you’ve got a run of 4 paragraphs, each with a different style, and you want to put them all together in a single anchored object, you’d need to find some way of creating a single GREP that will find all 4 styles. Perhaps one simple way of doing so would be to give them all a particular colour, and then create a GREP search that searches for that colour.
      Does that help?

  3. JohnnyCarbon

    April 2, 2021 9:07 pm Reply

    I like the idea of the script, it would help in law books where they want para numbers moving from the text to the outside edges of the page. However, once the book is printed they want a Word file back for editing for the next edition the following year. Would it be possible with this script to reverse this process so that the anchored text gets placed back in the text so that when you export it to Word from InDesign the customer receives the Word file back just like the one they sent but now updated?

    • Ariel

      April 4, 2021 2:59 am Reply

      I’m not sure about your idea. It depends how many paragraphs there are in the book, but having hundreds of anchored objects in a document can slow InDesign to a crawl. If you just need paragraph numbers in the margins, perhaps the “Line Numbers” script would serve you better. You could use Line Numbers to add paragraph numbers, and somehow hide the existing paragraph numbers (apply the “None” colour to them, perhaps, that sort of thing). Line Numbers wouldn’t slow up InDesign in any way:

      Re. your question about un-anchoring the objects, though, yes, there’s a free script for that here:

  4. Mauser

    October 27, 2020 1:19 pm Reply

    Anchored Object feature of the ones
    batch cancel , how can it be done

    • Ariel

      October 27, 2020 9:40 pm Reply

      Hi Mauser,
      I don’t really understand the question.
      But if you’re looking to move a bunch of anchored objects back into the main text flow, check this out: Anchored Text Uncaged

  5. Peter

    January 22, 2020 9:38 am Reply

    Thanks for your script, very useful!
    Do you develop reverse writing?
    For example:
    1: paragraph with “Para Style 1” to Anchored (your script)
    2: Anchored to initial position “Para style 1” (futur script ?)
    Thank you for your reply,


  6. Ariel

    February 3, 2019 2:42 am Reply

    Hi Kevin,
    Sure it can, but with a little help, since it’s not possible to search for 2 paragraph styles at once with a single GREP search.
    What you could do, though, is, for example, apply a special color to the text of all the paragraphs you want the script to pick up.
    Then, set up the GREP search to search for that color, rather than for specific paragraph styles.
    Does that make sense?

  7. Kevin Callahan

    February 1, 2019 9:39 pm Reply

    Hi, this looks like it could be a great help in preparing a document for epub export. Anchoring sidebars and other asides can be a pain in the neck, depending on how the InDesign user set up the document.

    Often, a sidebar will have a headline/title and then some paragraphs, so there could be at least 2 paragraph styles, sometimes more (if there’s also a bulleted list, for example). Can this script grab more than one paragraph style, extract them all, and place in an anchored text box? would be fabulous…..

  8. Daniela Weiland

    December 6, 2018 2:21 pm Reply

    I tried the script and it works fine. But is there also a possibility to copy the text only and don’t delete it?

    Best regards

    • Ariel

      December 8, 2018 11:02 pm Reply

      Hi Daniela,

      There is not a built-in way to do that. The text is moved into the anchored object and deleted from the main document.
      However, it should be fairly easy to duplicate the text first with a GREP find/change. At the same time you could apply a new colour to the copied text (or something like that). Then run GREP to Anchored Object only on text with the other colour.
      That way you will be left with a copy of the text in the main document as well…
      I could also customize the script to add this feature — get in touch if you would like a quote for that.

  9. seongjae weon

    September 17, 2018 6:26 pm Reply

    I tried to find grep in the text box and make it a “Grep to Anchored Object” I bought here.
    But it did not work.
    I am wondering how to create an anchored object exactly where the text box is located.
    If you can not achieve “Grep to Anchored Object”, I would like to know if you can provide a script to solve it.

    Best Regards,

    • Ariel

      September 17, 2018 7:43 pm Reply

      Send me an email to admin [at] and I’ll be happy to try and help create the right GREP expression to get the script working as needed!

  10. mayer

    March 21, 2018 11:14 pm Reply

    i have anchored-text box on top of each word and i would like to center it on every word
    is it possible to have a script to center each anchored-text box on top of a word

    • Ariel

      January 7, 2019 12:05 pm Reply

      It could be done, but would need a custom modification to get the word centred in relation to another word.
      However, I would advise against a setup like this, because having so many anchored objects will slow InDesign to a crawl. A better solution would be to set up a parallel text frame, not anchored, and add the translations in the correct places, avoiding dozens of anchored objects per page.

Leave a Comment