I am a beginner at writing scripts for InDesign (just started today!). I have somehow managed to write a script which auto-fills a text box with a list of the linked images within the document. However, when I group the text box with other objects or move it to another indesign doc, the script no longer works. I get an error that says "Object is invalid" with the source being "resFrame.contents = res.String;". Can someone please explain why this is happening and how it can be fixed?

Code below...

myDoc = app.activeDocument;  
myPages = myDoc.pages.everyItem().getElements();  
myDoc.viewPreferences.horizontalMeasurementUnits = myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES;  

for (var k = 0; k < myPages.length; k++) {  
    resString = myDoc.links.everyItem().name.join("\r");  
    resFrame = myFramelinks(myPages[k]);  
    resFrame.contents =  resString;

function myFramelinks (page) {
    var mFlinks = page.textFrames.item("linkslist");
    return mFlinks;

1 Answer 1


Where does your items name "linkslist" come from? By setting a name for the textFrame?

The "name" property of a textframe seems to be persistent for the document. Also if you copy paste the textframe to another doc it still is there.

But if you have a page with 2 textframes and you run:


it will return 2

Group these textframes together and it will return 0

If you want to access elements that are grouped you need to access them like this:

$.writeln (app.activeDocument.pages[0].groups[0].textFrames[0].name)

You also can access them this way:


This will return 3.

if you run:

for(var i = 0; i < app.activeDocument.pages[0].allPageItems.length; i++){

The output will be:


So you could create a check for your name and access that particular textFrame again.

(Tested in ID CC 2014 on OSX 10.10.2)


To retrieve the textframe with the name "linkslist" you should do something like this:

function get_linklist(page) {
  var tf = null;
  for (var i = 0; i < page.allPageItems.length; i++) {
    var item = page.allPageItems[i];
    if (item.name == "linkslist") {
      tf = item;
  return tf;

var doc = app.activeDocument;
var p = doc.pages[0];

var res = get_linklist(p);
if (res === null) {
  $.writeln(" :(");
} else {
  $.writeln(" :)");
  • Hi fabian, thanks for the input. I am having some difficulty incorporating this into my script - can you elaborate?
    – Emily
    Feb 18, 2015 at 22:36
  • I updated the post with some example code. Feb 19, 2015 at 6:04
  • so, the key is to iterate through an object (allPageItems) which doesn't cloak the text frames?
    – Yorik
    Feb 19, 2015 at 15:31
  • Exactly, if the textFrame is in the group he is a child of the group and not accessible via the textFrames collection Feb 19, 2015 at 19:31
  • It works!! Thank you so much. On another note, do you know how I can get the script to not list duplicate links?
    – Emily
    Feb 21, 2015 at 0:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.