Copy link to clipboard
Copied
I need to read the destination URL from an InDesign document with hyperlinks but can't figure out how to do it.
Here is a little script to try it out, it is the line set hyperLinkUrl to destination URL of theHyperLink that doesn't work.
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
I have tried a number of combinations but just can't get it to work.Any suggestions anyone, will it be easier to read it with a javascript?
The bad Applescript line should be:
set hyperLinkUrl to destination URL of destination of theHyperLink
Copy link to clipboard
Copied
Hi Fredrik,
I don't know much about Applescript. But in Javascript you could something like the following
for(var i = 0; i < app.documents[0].hyperlinks.length; i++)
alert(app.documents[0].hyperlinks.destination.destinationURL)
The above code will work with a document open and if the document has hyperlinks it will prompt with the destination URL of those hyperlink
-Manan
Copy link to clipboard
Copied
Thanks Manan, your javascript does get me exactly the information i need. Can i alter it so i get info for a specific hyperlink only and get the answer back in a applescript variable?
It is possible to call a javascript string within an applescript, like this.
set hyperLinkUrl to do script "for(var i = 0; i < app.documents[0].hyperlinks.length; i++) \n alert(app.documents[0].hyperlinks.destination.destinationURL)" language javascript
So in this case the javascript should just get the destination URL as text and not show a message window.
Copy link to clipboard
Copied
Hi Fredrik,
We can get information about a specific hyperlink, how do you intend to identify the hyperlink that you want to get information about. In the meanwhile playing around with Applescript a bit i got to get a sample working for your original use case have a look.
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 des to destination of theHyperLink
display dialog "URL " & destination URL of des
end repeat
end tell
-Manan
Copy link to clipboard
Copied
With my javascript programmer we managed to get it sorted.
set readURLscript to "for(var i = 0; i < app.documents[0].hyperlinks.length; i++) \n if (app.documents[0].hyperlinks.name=='" & hyperLinkName & "'){(app.documents[0].hyperlinks.destination.destinationURL)}"
Copy link to clipboard
Copied
The bad Applescript line should be:
set hyperLinkUrl to destination URL of destination of theHyperLink
Copy link to clipboard
Copied
Yes! A proper AppleScript solution that works, thank you so much!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more