4 Replies Latest reply on Jun 17, 2010 8:53 PM by sstanleyau

    help with hyperlinks in applescript indesign cs4

    conyip

      Hi there i am hoping that someone can help:

      I have written an applescript script to search a document, when the search text string matches the files loaded in a list from an external folder, a hyper link is created to this external file. see below:

       

      set the_folder to choose folder

      tell application "Finder"

       

      set files_list to every file of folder the_folder whose name extension is "pdf"

      end tell

       

      tell application "Adobe InDesign CS4"

       

      repeat with FileRef in files_list

      set FileName to name of FileRef

      set find text preferences to nothing

       

      --Search the document.

      set find what of find text preferences to FileName

      --Set the find options.

      set case sensitive of find change text options to false

      set include footnotes of find change text options to true

      set include hidden layers of find change text options to false

      set include locked layers for find of find change text options to false

      set include locked stories for find of find change text options to false

      set include master pages of find change text options to false

      set whole word of find change text options to false

      tell active document

      set myFoundItems to (find text) as string

       

       

       

      if FileName = myFoundItems then

      set FileNewName to name of FileRef as string

      set TxtName to name of FileRef

      set TheURL to "files:files/" & FileNewName

       

       

      try

      set TheH to make hyperlink URL destination with properties {name:TxtName, destination URL:TheURL}

      on error

      set TheH to hyperlink URL destination TxtName

      end try

       

      set TheHSName to "HS" & TxtName

       

       

      set TheHS to make hyperlink text source with properties {name:myFoundItems, source text:myFoundItems, hidden:false} <<error on this line

       

       

       

      make new hyperlink with properties {destination:TheH, source:TheHS, visible:false}

       

      end if

       

      end tell

       

      end repeat

       

       

      end tell

       

      however I keep getting an error: "Adobe InDesign CS4 got an error: Can't get hyperlink text source text expected but got \"applescript.pdf\"."

       

      I can not figure it out as the text source is a string..

      thanks

       

      Keith

        • 1. Re: help with hyperlinks in applescript indesign cs4
          sstanleyau Level 4

          The source text of a hyperlink text source requires a reference to the the bit of text you want to be the source, not its contents.

          1 person found this helpful
          • 2. Re: help with hyperlinks in applescript indesign cs4
            conyip Level 1

            Thanks a lot for the reply,, this is so frustrating, and sorry for not being able to see it, but can you give an example..

            keith

            • 3. Re: help with hyperlinks in applescript indesign cs4
              sstanleyau Level 4

              This is untested, but should get you close:

               

              set the_folder to choose folder

              tell application "Finder"

              set files_list to every file of folder the_folder whose name extension is "pdf"

              end tell

               

              tell application "Adobe InDesign CS4"

              repeat with FileRef in files_list

              set FileName to name of FileRef

              set find text preferences to nothing

              set find what of find text preferences to FileName

              --Set the find options.

              set case sensitive of find change text options to false

              set include footnotes of find change text options to true

              set include hidden layers of find change text options to false

              set include locked layers for find of find change text options to false

              set include locked stories for find of find change text options to false

              set include master pages of find change text options to false

              set whole word of find change text options to false

              tell active document

              set myFoundItems to find text -- search; returns list of object references

              if myFoundItems is not {} then

              -- make a single destination

              set TheURL to "files:files/" & FileName

              if not (exists hyperlink URL destination FileName) then

              set TheH to make hyperlink URL destination with properties {name:FileName, destination URL:TheURL}

              else

              set TheH to hyperlink URL destination FileName

              end if

              repeat with i from 1 to count of myFoundItems

              set TheHSName to "HS" & FileName & "-" & i -- if you don't want the default name, you have to make it unique

              set TheHS to make hyperlink text source with properties {name:TheHSName, source textitem i of myFoundItems), hidden:false}

              make new hyperlink with properties {destination:TheH, source:TheHS, visible:false}

              end repeat

              end if

              end tell

              end repeat

              end tell

               

              • 4. Re: help with hyperlinks in applescript indesign cs4
                sstanleyau Level 4

                Actually, while that fixes your hyperlink stuff, you have problems earlier on with your file names and URLs -- you can't build URLs like that. Try something like this:

                 

                set the_folder to choose folder

                tell application "Finder"

                set files_list to name of every file of folder the_folder whose name extension is "pdf"

                set url_list to URL of every file of folder the_folder whose name extension is "pdf"

                end tell

                 

                tell application "Adobe InDesign CS4"

                set find text preferences to nothing

                --Set the find options.

                set case sensitive of find change text options to false

                set include footnotes of find change text options to true

                set include hidden layers of find change text options to false

                set include locked layers for find of find change text options to false

                set include locked stories for find of find change text options to false

                set include master pages of find change text options to false

                set whole word of find change text options to false

                repeat with j from 1 to count of files_list

                set FileName to item j of files_list

                set TheURL to item j of url_list

                set find what of find text preferences to FileName

                tell active document

                set myFoundItems to find text -- search; returns list of object references

                if myFoundItems is not {} then

                -- make a single destination

                if not (exists hyperlink URL destination FileName) then

                set TheH to make hyperlink URL destination with properties {name:FileName, destination URL:TheURL}

                else

                set TheH to hyperlink URL destination FileName

                end if

                repeat with i from 1 to count of myFoundItems

                set TheHSName to "HS" & FileName & "-" & i -- if you don't want the default name, you have to make it unique

                set TheHS to make hyperlink text source with properties {name:TheHSName, source text: (item i of myFoundItems), hidden:false}

                make new hyperlink with properties {destination:TheH, source:TheHS, visible:false}

                end repeat

                end if

                end tell

                end repeat

                end tell