Skip to main content
Inspiring
Nov 21, 2019 6:20 PM UTC
Answered

Script to Extract hyperlinks from Indesign File with Page number

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

Manan JoshiCorrect answer
Community Expert
Feb 12, 2020 11:58 AM UTC

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

-Manan

31 replies

Community Expert
Aug 17, 2022 4:43 PM UTC

@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 )

Translate
M.Hasanin
Inspiring
Aug 17, 2022 6:09 PM UTC

@Laubender 

Thanks a lot, it works!

Translate
Mohammad Hasanin
Manan JoshiCommunity ExpertCorrect answer
Community Expert
Feb 12, 2020 11:58 AM UTC

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

Translate
-Manan
Inspiring
Nov 21, 2019 6:20 PM UTC

Hi, I need script to extract URLs from indesign files to notepad with page number on which url is located,

 

Translate
brian_p_dts
Community Expert
Community Expert
Nov 21, 2019 8:02 PM UTC

Are you comfortable writing this script yourself, or do you need someone to do it for you? The page number is in the document.page[i].name field. The URL could be found through a GREP search on the text. Setting up the log file is relatively straightforward using File objects. If you need help writing the script, happy to do it for a nominal fee. Feel free to PM. 

Translate
Community Expert
Feb 12, 2020 10:55 AM UTC

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

Translate
-Manan
Inspiring
Feb 12, 2020 11:26 AM UTC

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();  
} 

Translate
Jongware
Community Expert
Community Expert
Feb 12, 2020 1:53 PM UTC

> ... 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?

Translate