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

Script to Extract hyperlinks from Indesign File with Page number

Participant ,
Feb 12, 2020 Feb 12, 2020

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

3.3K

Likes

Translate

Translate

Report

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

Community Expert , Feb 12, 2020 Feb 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(
...

Likes

Translate

Translate
Community Expert ,
Feb 12, 2020 Feb 12, 2020

Copy link to clipboard

Copied

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

 

-Manan

Likes

Translate

Translate

Report

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
Participant ,
Feb 12, 2020 Feb 12, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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
LEGEND ,
Feb 12, 2020 Feb 12, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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 ,
Feb 12, 2020 Feb 12, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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
Participant ,
Nov 21, 2019 Nov 21, 2019

Copy link to clipboard

Copied

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

 

Likes

Translate

Translate

Report

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 ,
Nov 21, 2019 Nov 21, 2019

Copy link to clipboard

Copied

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. 

Likes

Translate

Translate

Report

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
Participant ,
Nov 22, 2019 Nov 22, 2019

Copy link to clipboard

Copied

I have code which extract hyperlinks (urls) from indd file to notepad, but i need page number where that specific url is in the 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();  

 

Below is the example how urls look like in file

.Capture.PNG

Likes

Translate

Translate

Report

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 ,
Nov 21, 2019 Nov 21, 2019

Copy link to clipboard

Copied

Hi,

are the URLs all visible in the Hyperlinks panel?

Are there also buttons with gotoURLBehaviors that contain URLs you want to pick up?

Any text that contains URL like contents that is just plain text?

 

Regards,
Uwe Laubender

( ACP )

Likes

Translate

Translate

Report

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
Participant ,
Nov 22, 2019 Nov 22, 2019

Copy link to clipboard

Copied

yes, they are visible in hyperlinks panel. and like below in file

 

Capture.PNG

Likes

Translate

Translate

Report

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
Participant ,
Nov 22, 2019 Nov 22, 2019

Copy link to clipboard

Copied

I have below code to extract URLs (hyperlinks) from INDD file to notepad, but i need the page number where the specific urls is in 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();  

Likes

Translate

Translate

Report

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 ,
Nov 22, 2019 Nov 22, 2019

Copy link to clipboard

Copied

Look into the property source of object Hyperlink.

 

That's the key to the position of an individual hyperlinkTextSource ( source.sourceText.parentTextFrames array ) and hyperlinkPageItemSource ( source.sourcePageItem ).

 

From that you could see into property parentPage.

 

If the text container or the page item is not e.g. on the pasteboard or in overset text, you should be able to retrieve parentPage.documentOffset which is the sequential number of the page within the document. Or parentPage.name .

 

DOM documentation:

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

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

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

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

 

Regards,
Uwe Laubender

( ACP )

Likes

Translate

Translate

Report

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
Enthusiast ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

@Manan Joshi 

 

Folder.myDocuments

 

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

Best
M.Hasanain

Likes

Translate

Translate

Report

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 ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

I work on a MAC so surely I would have tested and it would have worked. I see no reason why it should not work on WIN machine as well. Give it a try and let me know if it does not. However, it should be an easy fix that I am sure you will take care of.

-Manan

Likes

Translate

Translate

Report

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
Enthusiast ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

Thanks @Manan Joshi 

Yes it Works in Windows too, Thank you again

Best
M.Hasanain

Likes

Translate

Translate

Report

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 ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

@M.Hasanain 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 )

Likes

Translate

Translate

Report

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
Enthusiast ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

LATEST

@Laubender 

Thanks a lot, it works!

Best
M.Hasanain

Likes

Translate

Translate

Report

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