3 Replies Latest reply on Jun 23, 2013 4:25 AM by Janaaaaa

    applescript 2 scripts to one (grep+add hyperlink)

    Janaaaaa

      Hi.

       

      I try to combine two scripts. First one greps 7 digits numbers in indesign

      and another makes hyperlink that is same numbers as that selection(grep)'

      Does anyone have  idea how to do that. thanks -Jan

       

      This  greps 7 digits numbers in indesign with this script

      tell application "Adobe InDesign CS5.5"

        activate

                set find grep preferences to nothing

                set change grep preferences to nothing

                set find what of find grep preferences to "\\d{7}"

                tell active document

                          set myFoundItems to find grep

                end tell

      end tell

       

      and this one makes hyperlink:

       

      tell application "Adobe InDesign CS5.5"

       

                tell document 1

                          set mySelection to selection

       

                          set LinkID to contents of mySelection as string

                          set LinkIDURL to LinkID as string

       

                          try

                                    set URL_L to make hyperlink URL destination with properties {name:LinkID, destination URL:LinkIDURL}

                          on error

                                    set URL_L to hyperlink URL destination LinkID

                          end try

                          set URL_La to make hyperlink text source with properties {source text: (item 1 of mySelection), hidden:false}

                          set myHyperlink to make new hyperlink with properties {destination:URL_L, source:URL_La, visible:false}

       

                end tell

      end tell

      end


       

       


        • 1. Re: applescript 2 scripts to one (grep+add hyperlink)
          Janaaaaa Level 1

          well. I have been searching from this forum and almost I figured this one out.

          But it only copies one item of many 7 digit number from indesign and makes that one hyperlink.

          other ones are not made. this is difficult Any ideas?

           

          tell application "Adobe InDesign CS5.5"

           

            activate

                    set find grep preferences to nothing

                    set change grep preferences to nothing

                    set find what of find grep preferences to "\\d{7}"

                    tell active document

                              set myFoundItems to find grep

                              repeat with i from 1 to count of myFoundItems

                                        set FileName to (contents of item 1 of myFoundItems) as string

           

                                        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

           

                                        set TheHSName to FileName

                                        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 tell

          end tell


          • 2. Re: applescript 2 scripts to one (grep+add hyperlink)
            Larry G. Schneider Adobe Community Professional & MVP

            You may need to run the loop backwards to not ruin the index.

            • 3. Re: applescript 2 scripts to one (grep+add hyperlink)
              Janaaaaa Level 1

              YES! I got it with help of Indesign scripting quide.

               

              Here is the applescript. Feel free to use if you need. This only works if no hyperlinks are not assignet to those 7 digits you are grepping with this script

               

              tell application "Adobe InDesign CS5.5"

               

                activate

                -- resetoi grep opitonit ettei edelliset haut vaikuta

                        set find grep preferences to nothing

                        set change grep preferences to nothing

               

               

                --Asettaa haku parametrit

               

                        set include hidden layers of find change grep options to false

                        set include locked layers for find of find change grep options to true

               

                -- 7 numero perakkain hakuaehto

                        set find what of find grep preferences to "\\d{7}"

               

                        tell active document

                -- etsii jokaisen sivulla oleva mallikoodin nimen

                                  set myFoundItems to find grep

                -- ottaa ylos jokaisen mallikoodin numerosarjan

                                  repeat with i from 1 to (count myFoundItems)

                                            set FileName to contents of item i of myFoundItems

               

                                            if not (exists hyperlink URL destination FileName) then

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

                                            else

                                                      set TheH to hyperlink URL destination FileName

                                            end if

               

               

                -- lisaa hyperlinkin

               

                                            set TheHSName to FileName

                                            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 tell

              end tell