Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Find and Unlink Text Links [CS6] [JS]

New Here ,
Oct 30, 2013 Oct 30, 2013

We are getting InDesign CS6 documents. Most of these documents have .txt files placed as links. Does anyone have a script that will check an open document for txt links and if one or  more exists, unlink them. This seems to work, but I don't know what else it is unlinking...

app.activeDocument.links.everyItem().unlink()

I don't really feel safe using this because other images or links I want to keep could be deleted with this. I would like to narrow it down to look for and unlink txt files only.

I'd really appreciate any help! Thanks in advance!

Danny

TOPICS
Scripting
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Oct 30, 2013 Oct 30, 2013

You could loop through all links, and check their names, something like this:

var link;

var linkName;

var links = app.activeDocument.links;

for (var i=links.length-1; i>=0; i--){

    link = links;

    linkName = link.name;

    if (link.name.substr(linkName.length-4) == '.txt'){

        link.unlink();

    }

}

Translate
Enthusiast ,
Oct 30, 2013 Oct 30, 2013

You could loop through all links, and check their names, something like this:

var link;

var linkName;

var links = app.activeDocument.links;

for (var i=links.length-1; i>=0; i--){

    link = links;

    linkName = link.name;

    if (link.name.substr(linkName.length-4) == '.txt'){

        link.unlink();

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 30, 2013 Oct 30, 2013

Hm.

I'd rather check for the parent object of a particular link.

If it's a Story object, it's safe to assume you have a linked text file.

var d=app.documents[0];

var allTheLinks = d.links;

for(var n=allTheLinks.length-1;n>=0;n--){

    var link = allTheLinks;

    if(link.parent.getElements()[0].constructor.name === "Story"){link.unlink()};

    };

The advantage is that you need not to look for every file extension or possible kind of file associated with a text file.

Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 31, 2013 Oct 31, 2013
LATEST

Both work perfect for what I need. Thanks for your help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines