The following script is a short and sweet way of moving all text in an InDesign anchored object out of its little cage and into the main text flow of the document.

If you have an InDesign document peppered with anchored objects containing text (perhaps some sort of subhead system) and you want to move all that text back into the main flow of the InDesign document and delete the anchored object, this script does that.

The script will move all text out of its anchored object, and, keeping formatting intact, insert it just before the anchored object marker in the main text flow containing the anchored object. It will then delete the anchored object itself.

Instructions

Always back up your document first!

1. Set up a GREP find/change query that will find all the text you are interested in “uncaging”. (This is done in InDesign’s Find/Change window, under the GREP tab; if you are not familiar with GREP, this is a good opportunity to become so – it’s very powerful and an essential tool for any InDesign user.)

2. Once the GREP search is set up as you like, run the script. (You may close the Find/Change window. You do not need to click on Find Next or Find All – it is sufficient just to set up the GREP query.)

Finito! The script will find all text in the document that matches the GREP search. If that text is in an anchored object, the script will then move all the text in the anchored object out of it’s box and into the main text flow, and the script will then delete the anchored object itself.

Here’s the script:

//BS"D
//Anchored Text Uncaged
//An InDesign script Copyright (c) Bookraft LLC, 2015
//Another freebie script from www.Id-Extras.com
// This code is released under the GNU Public License (GPL)

main();

function main(){
   var d, fs, i, f, p;
   d = app.activeDocument;
   fs = d.findGrep(true);
   for (i = 0; i < fs.length; i++){
      f = fs[i];
      if ((p = f.parentTextFrames[0].parent) instanceof Character){
         f.parent.texts.everyItem().move(LocationOptions.BEFORE, p);
         p.contents = "";
      }
   }
}

If you need this script expanded or developed to meet your needs please get in touch to request a quote!

Questions and comments welcome below.