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

How do I loop through selected links?

Community Beginner ,
Mar 18, 2015 Mar 18, 2015

Hi!

I'm looking for clues on how to run a script on selected links (selected in the Links window).

Like this sample script that runs an alert when links are missing:

var aDoc = app.activeDocument;

for(var n = 0; n < aDoc.links.length; n++) {

     var aLink = aDoc.links;

     if (aLink.status == LinkStatus.linkMissing) {

          alert(aLink.filePath);

     }

}

Is there something like LinkStatus.linkSelected?

Or some other way for the script to sort out the selected links.

Any input would be extremely appreciated!

Thanks!

/Peter

TOPICS
Scripting
689
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

Mentor , Mar 19, 2015 Mar 19, 2015

Hi,

As far as I know - not possible to read selection from Link Panel (any UI Panel).

Other solution?

- to create a dialog with listBox (each list item is a link read from a doc) and "multiselect" property set as "true".

This way user can select a set of links and script can do a job based on selection.

Jarek

Translate
Community Beginner ,
Mar 19, 2015 Mar 19, 2015

So, I got a little further. But this script only works with links selected in the documents or the layer tab.

Could anyone point me to how it's done if the link is selected in the links tab?

If its not possible just tell me. Or if you have any other solution I'd be happy to hear that as well.

Current script:

var sel = app.activeDocument.properties.selection;

for(var n = 0; n < sel.length; n++) {

    if(sel == '[object Image]'){

        // Directly selected image

        aLink=sel.itemLink.filePath;

    }

    else{

        // Rectangle selected

        aLink=sel.graphics[0].itemLink.filePath;

    }

alert(aLink);

}

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
Mentor ,
Mar 19, 2015 Mar 19, 2015

Hi,

As far as I know - not possible to read selection from Link Panel (any UI Panel).

Other solution?

- to create a dialog with listBox (each list item is a link read from a doc) and "multiselect" property set as "true".

This way user can select a set of links and script can do a job based on selection.

Jarek

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 Beginner ,
Mar 19, 2015 Mar 19, 2015

Thanks for the reply!

I'll look inte the listBox option. That looks like the way to go.

Peter

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
People's Champ ,
Mar 19, 2015 Mar 19, 2015

We should definitively harass Adobe to be offered such accesses. Of course one may write a c library and deal with that but it's far outside my skills fro what I am concerned.

Just saying

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 Beginner ,
Mar 19, 2015 Mar 19, 2015

@Loic yes. You are absolutley right. I'm really surprised that its not accessable already.

But if things go as I plan, my scripted links window will be better than the one that comes with InDesign. That is if I can work out how to format it right.

I'm really new to scripting Adobe programs, and the options are quite limited at times.

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
Mentor ,
Mar 20, 2015 Mar 20, 2015

Hi Peter,

You could start with this:

function mDialog()

{

  var

  u = undefined,

  mRes = [], cItem, cLink,

  mLinksNames = app.activeDocument.links.everyItem().name,

  // ||||||||||||||||| dialog body |||||||||||||

  mWin = new Window ("dialog", "Link manager", u, {closeButton: false}),

  mList = mWin.add("listbox", u, mLinksNames, {multiselect: true}),

  buttLine = mWin.add("group");

  buttLine.add("button", u, "OK", {name: "OK"});

  buttLine.add("button", u, "Cancel", {name: "Cancel"});

  // ||||||||||||||||| output |||||||||||||

  if (mWin.show() == 1) {

  var listSelection = mList.selection;

  while ( cItem = listSelection.shift() ) {

  cLink = app.activeDocument.links.itemByName(cItem.text);

  mRes.push(cLink);

  }

  return mRes;

  }

  else exit();

  }

var mSelected = mDialog();

Variable mSelected is empty array or array with selected links

You could use is for further code.

Some question is what to do with repeated links (list unique only?).

Jarek

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 ,
Mar 20, 2015 Mar 20, 2015

@Jarek – hm, "list unique only" will give no flexibility. I'd list all the links.

And: Uniqueness in "name" is not uniqueness in "linked files".

Could mean big trouble not to show every instance of a link.

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
Mentor ,
Mar 20, 2015 Mar 20, 2015
LATEST

Hi,

I would modify line #17:

while (listSelection && cItem = listSelection.shift() ) {


cause empty selection leads to error.


Uwe,

In case of unique - troubles could depends on what are you going to do with output and how.

If we talk about dialog list only - it is much more comfortable to user just to select a link name once instead of - let say - 125 clicks (in theory).

But maybe a better idea is to return just an array of names and convert it to useful list of object (one name into many links) outside of mDialog function()

Jarek

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