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

Get destination URL with AppleScript

Explorer ,
Apr 01, 2019 Apr 01, 2019

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?

TOPICS
Scripting
1.2K
Translate
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

Participant , Apr 01, 2019 Apr 01, 2019

The bad Applescript line should be:

   

     set hyperLinkUrl to destination URL of destination of theHyperLink

Translate
Community Expert ,
Apr 01, 2019 Apr 01, 2019

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

Translate
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
Explorer ,
Apr 01, 2019 Apr 01, 2019

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.

Translate
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 ,
Apr 01, 2019 Apr 01, 2019

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

Translate
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
Explorer ,
Apr 01, 2019 Apr 01, 2019

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)}"

Translate
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 ,
Apr 01, 2019 Apr 01, 2019

The bad Applescript line should be:

   

     set hyperLinkUrl to destination URL of destination of theHyperLink

Translate
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
Explorer ,
Apr 01, 2019 Apr 01, 2019
LATEST

Yes! A proper AppleScript solution that works, thank you so much!

Translate
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