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

"Copy Link(s) to…" using javascript

New Here ,
May 06, 2014 May 06, 2014

Could you show me how to write a javascript that can do the "Copy Link(s) to…"? It would be time consuming to do it manually. Thanks in advance.

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

Mentor , May 06, 2014 May 06, 2014

Hi,

copyLink(File) is a link's method.

However "How to write javascript" mostly depends on assumings.

Below code assumes:

Every valid link from active document is copied to destFolder keeping current file name.

var

  mDoc = app.activeDocument,

  mLinks = mDoc.links.everyItem().getElements(),

  destFolder = "~/Desktop/copiedLinks/",

  currLinkFName, currFile,

  len = mLinks.length;

if ( !Folder(destFolder).create() ) exit();

while (len-->0) {

  currLinkFName = mLinks[len].filePath;

  currFile = F

...
Translate
Mentor ,
May 06, 2014 May 06, 2014

Hi,

copyLink(File) is a link's method.

However "How to write javascript" mostly depends on assumings.

Below code assumes:

Every valid link from active document is copied to destFolder keeping current file name.

var

  mDoc = app.activeDocument,

  mLinks = mDoc.links.everyItem().getElements(),

  destFolder = "~/Desktop/copiedLinks/",

  currLinkFName, currFile,

  len = mLinks.length;

if ( !Folder(destFolder).create() ) exit();

while (len-->0) {

  currLinkFName = mLinks[len].filePath;

  currFile = File( destFolder + File(currLinkFName).name );

  if (File(currLinkFName).exists)

  mLinks[len].copyLink(currFile);

  }

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
New Here ,
May 13, 2014 May 13, 2014

Jump_Over,

Thanks, I will give it a try.

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 ,
May 13, 2014 May 13, 2014

Wow, it worked. You are awesome. I have been trying to figure that out for weeks. Now, I have to figure it out how to replace the deskFolder with the user input.

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 ,
May 13, 2014 May 13, 2014

Hi,

1. Change a "correct" answer to mine, pls

2. In case of user input you can modify the line:

destFolder = Folder.selectDialog("Show me a target folder") + "/";

Is it helpful

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
New Here ,
May 13, 2014 May 13, 2014

Jarek,

Yesss, I should have gone to this forum a long time ago. I am running to a problem. I have several identical links in my Indesign file, when I run the script, Indesign stopped and said "the link already exists (because it can not "save" over the existing one in the same folder). Is there a way I can bypass this. Something like

if (currFile.exists)

// bypass this command

Sorry, I am notice to Javascript. I am so excited to learn Javascript. Thanks for helping.

I am an expert in Indesign (non-script) of course, please ask me if you had any question in that area.

Phong

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 ,
May 13, 2014 May 13, 2014
LATEST

Hi,

Right, It can result with error. To bypass modify this line:

if ( !currFile.exists && File(currLinkFName).exists )

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