Skip to main content
Inspiring
November 21, 2019
Answered

Script to Extract hyperlinks from Indesign File with Page number

  • November 21, 2019
  • 3 replies
  • 8732 views

Anyone have any script to extract hyperlinks from Indesign File with location (i.e with page number) 

Correct answer Manan Joshi

Try the following

var list = [];  
for (a=0; a<app.activeDocument.hyperlinks.length; a++)  
{  
	try
	{  
		d = app.activeDocument.hyperlinks[a].destination.destinationURL;  
		if (d.match(/^http/))  
		{
			var b = app.activeDocument.hyperlinks[a].source
			var page
			if(b.constructor.name == "HyperlinkPageItemSource")
				page = b.sourcePageItem.parentPage.name
			else if(b.constructor.name == "HyperlinkTextSource")
				page = b.sourceText.parentTextFrames[0].parentPage.name
			
			$.writeln(page)
			list.push ("Page Name " + page + " " + d); 
		}
	} catch(_) {}  
}  
// show the list  
alert ('All links:\r'+list.join('\r'));  
// save the list as a file  
listFile = new File(Folder.myDocuments+"/all_links.txt");  
if (listFile.open("w"))  
{  
  listFile.writeln(list.join('\n'));  
  listFile.close();  
  listFile.execute();  
} 

 

-Manan

3 replies

Community Expert
August 17, 2022

@M.Hasanin said:

Folder.myDocuments

"Im Wondering if this folder path will work in both Windows and Mac ? "

 

Hi,

you can look up property myDocuments for object Folder in the DOM documentation.

Scroll down to the second list of properties:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Folder.html

 

On my Windows 10 machine it returns:

~/Documents

 

Also try this and see what folder opens in the file explorer:

Folder.myDocuments.execute();

 

Regards,
Uwe Laubender
( Adobe Community Professional )

M.Hasanin
Inspiring
August 17, 2022

@Laubender 

Thanks a lot, it works!

BestMohammad Hasanin
Manan JoshiCorrect answer
Community Expert
February 12, 2020

Try the following

var list = [];  
for (a=0; a<app.activeDocument.hyperlinks.length; a++)  
{  
	try
	{  
		d = app.activeDocument.hyperlinks[a].destination.destinationURL;  
		if (d.match(/^http/))  
		{
			var b = app.activeDocument.hyperlinks[a].source
			var page
			if(b.constructor.name == "HyperlinkPageItemSource")
				page = b.sourcePageItem.parentPage.name
			else if(b.constructor.name == "HyperlinkTextSource")
				page = b.sourceText.parentTextFrames[0].parentPage.name
			
			$.writeln(page)
			list.push ("Page Name " + page + " " + d); 
		}
	} catch(_) {}  
}  
// show the list  
alert ('All links:\r'+list.join('\r'));  
// save the list as a file  
listFile = new File(Folder.myDocuments+"/all_links.txt");  
if (listFile.open("w"))  
{  
  listFile.writeln(list.join('\n'));  
  listFile.close();  
  listFile.execute();  
} 

 

-Manan

New Participant
November 8, 2023

hi, it is not work for Indeign 2024?

 

Thanks

Community Expert
March 26, 2025

What do you get? Do you see an error or something. Please give more details.

-Manan

Community Expert
February 12, 2020

Hi Abhijeet,

 

This thread seems to be similar to the following thread by you. Any specific reason to open up a new thread? Did the solution provided by Uwe in the previous thread not work for you? You did not respond to his suggestions

https://community.adobe.com/t5/indesign/script-to-extract-url-from-indesign-file-to-txt-document-with-page-number/td-p/10754550?page=1

 

-Manan

Inspiring
February 12, 2020

Sorry it dosen't work for me, I have zero knowledge regarding scripting, So I need a complete script which can provide the list of URL'S present in InDesign file in txt file along with page number. 

I have below Script which Extract all hyperlinks from InDesign file in new .txt file.

 

var list = [];  
for (a=0; a<app.activeDocument.hyperlinks.length; a++)  
{  
try {  
  d = app.activeDocument.hyperlinks[a].destination.destinationURL;  
  if (d.match(/^http/))  
   list.push (d);  
} catch(_) {}  
}  
// show the list  
alert ('All links:\r'+list.join('\r'));  
// save the list as a file  
listFile = new File(Folder.myDocuments+"/all_links.txt");  
if (listFile.open("w"))  
{  
  listFile.writeln(list.join('\n'));  
  listFile.close();  
  listFile.execute();  

Jongware
Community Expert
February 12, 2020

> ... I have zero knowledge regarding scripting, So I need a complete script which does  [x, y, and z] ...

 

That explains why you have been asking for free scripts for the past three years. Any chance we can get paid by now?