Get destination URL from hyperlink in InDesign

Does somebody here know how to read the destination URL from a hyperlink in InDesign.
I have made a script that creates hyperlinks from some objects in the document and the next step is to check that everything matches up.


tell application "Adobe InDesign CC 2017"
	activate
	set myHyperlinks to every hyperlink of active document
	set numberOfHyperlinks to count myHyperlinks
	
	repeat with theHyperLink in myHyperlinks
		set hyperLinkName to name of theHyperLink
		set hyperLinkUrl to destination URL of theHyperLink --This line does not work
		display dialog "hyperLinkName: " & hyperLinkName & return & "hyperLinkUrl: " & hyperLinkUrl
	end repeat
end tell

Hi. You want the destination’s destination URL.

Yes! Sorry i could have explained a little better.

I have made a script that creates hyperlinks on images that meet some criteria in the document and most times it works just fine. But for some documents i get the wrong url and i can’t really figure out why. Sometimes it works when i delete text only layers and sometimes not. So there is something fishy about those documents that doesn’t work properly.

Since the url is based on the images name i thought i could do a check routine instead, i’m also labelling the hyperlinks with the image name so i thought it would be cleaver to just compare the hyperlink name with the url and get a warning if they doesn’t match up.

But when trying to get the url i got stuck.

Hi,

maybe this helps:

From this window you can copy/get the text…

Kind Regards,

Eric

You mean by selecting the window and copy? Not sure how to do that without using System Events and mimic a user and that is perhaps not the most elegant solution.

Had to use javascript to get this to work and this is my solution.

set readURLscript to "for(var i = 0; i < app.documents[0].hyperlinks.length; i++)  \n    if (app.documents[0].hyperlinks[i].name=='" & hyperLinkName & "'){(app.documents[0].hyperlinks[i].destination.destinationURL)}"
			set hyperLinkUrl to do script readURLscript language javascript

So inserted into the above script it would look like this.


tell application "Adobe InDesign CC 2017"
	activate
	set myHyperlinks to every hyperlink of active document
	set numberOfHyperlinks to count myHyperlinks
	
	repeat with theHyperLink in myHyperlinks
		set hyperLinkName to name of theHyperLink
		set readURLscript to "for(var i = 0; i < app.documents[0].hyperlinks.length; i++)  \n    if (app.documents[0].hyperlinks[i].name=='" & hyperLinkName & "'){(app.documents[0].hyperlinks[i].destination.destinationURL)}"
		set hyperLinkUrl to do script readURLscript language javascript
		display dialog "hyperLinkName: " & hyperLinkName & return & "hyperLinkUrl: " & hyperLinkUrl
	end repeat
end tell

As Marc Anthony pointed out above, the modification shown below should work:


tell application id "com.adobe.indesign"
	activate
	set myHyperlinks to every hyperlink of active document
	set numberOfHyperlinks to count myHyperlinks
	
	repeat with theHyperLink in myHyperlinks
		set hyperLinkName to name of theHyperLink
		
		set hyperLinkUrl to destination URL of destination of theHyperLink --  MODIFIED
		display dialog "hyperLinkName: " & hyperLinkName & return & "hyperLinkUrl: " & hyperLinkUrl
	end repeat
end tell

Yes! I read Marks answer as a question of what i wanted to do, not realising it was also the answer.

set hyperLinkUrl to destination URL of destination of theHyperLink

does work just fine.