title: Adding hyperlink to image in Indesign with Applescript
body: <p>I'm trying to create an AppleScript that creates hyperlinks on every linked image in InDesign.</p>
  
  <p>This is what I have come up with so far.</p>
  
  <pre><code>tell application "Adobe InDesign CC 2017"
    activate
    tell active document
    set grphicBoxs to all graphics of layer activeLayer
    set myLinks to {}
    repeat with I in grphicBoxs
    set iLink to item link of i
    set end of myLinks to iLink
    end repeat
  
    repeat with theLinkRef in myLinks
    set theLinkName to ((name of theLinkRef) as string)
    display dialog "theLinkName: " &amp; theLinkName
  
    set myHyperLink to "www.myURL"
    set myHyperLinkName to "myURL name"
  
    try
    set hyperLinkPreSet to make hyperlink URL destination with properties `{name:myHyperLinkName, destination URL:myHyperLink}`
    on error
    set hyperLinkPreSet to hyperlink URL destination myHyperLinkName
    end try
  
  
    try
    set hyperLinkObject to make hyperlink page item source with properties `{name:myHyperLinkName, source page item:rectangle theLinkName, hidden:false}`
    on error
    set TheHS to hyperlink page item source myHyperLinkName
    end try
  
    display dialog "hyperLinkObject:" &amp; hyperLinkObject
  
    make new hyperlink with properties `{destination:myHyperLink, source:hyperLinkObject, visible:false}`
  
  
    end repeat
  
    end tell
  end tell
  </code></pre>
  
  <p>The expected result is that the hyperlink preset that is created is applied to the chosen object. But I get this error message. </p>
  
  <blockquote>
    <p>Invalid value for parameter 'source' of method 'make'. Expected page
    item, but received nothing.</p>
  </blockquote>
  
  <p>Is there anyone here who has successfully created hyperlinks on linked objects who can help me?</p>