0

I'm trying to create an AppleScript that creates hyperlinks on every linked image in InDesign.

This is what I have come up with so far.

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: " & 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:" & hyperLinkObject

  make new hyperlink with properties `{destination:myHyperLink, source:hyperLinkObject, visible:false}`


  end repeat

  end tell
end tell

The expected result is that the hyperlink preset that is created is applied to the chosen object. But I get this error message.

Invalid value for parameter 'source' of method 'make'. Expected page item, but received nothing.

Is there anyone here who has successfully created hyperlinks on linked objects who can help me?

dpapadopoulos
  • 1,834
  • 5
  • 23
  • 34
Fredrik M
  • 1
  • 1

1 Answers1

0

Problem solved

set activeLayer to "Layer 1" set counter to 1

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)
       set theLinkNameNoext to text 1 thru ((offset of "." in theLinkName) - 1) of theLinkName

       set myHyperLink to "http://macscripter.net"
       set myHyperLinkName to theLinkNameNoext & " " & counter

       make hyperlink with properties {name:myHyperLinkName, source:make hyperlink page item source with properties {source page item:rectangle counter}, destination:make hyperlink URL destination with properties {destination URL:myHyperLink}}

       set counter to counter + 1
   end repeat

end tell end tell

Fredrik M
  • 1
  • 1