3 Replies Latest reply on Aug 25, 2015 11:00 AM by greenrookie

    relink problem

    JonnyDL Level 1

      Im writing a script that will take the color images from indesign, copy them, change them to grayscale (and rename them) then take those files and relink them (replace them with the grayscale). I've seen examples and it appears simple enough, but I can't get it to work *it still has a few bugs/and syntax issues Im looking to clean up

      here is the script. hopefully someone can see where the error is coming from and hopefully explain why.

      Thanks

       

      global picfolder

      global origimages

      global bwname

       

      set bwname to "color"

      tell application "Finder"

        set myhome to (path to home folder) as string

        set picfolder to myhome & "Documents:Dark Side:"

       

        if (exists (folder picfolder)) then

        movePics(picfolder) of me

        else

        make new folder at myhome & "Documents" with properties {name:"Dark Side"}

        end if

        set myPath to (path to home folder) as string

       

      end tell

      -------------------test to see if files are already there------------------------------------

      -------------------test to make sure original files still are there---------------------------

      on movePics()

        tell application "Adobe InDesign CS6"

        tell document 1

        set linkList to file path of every link

        repeat with linknumber from 1 to count of linkList

        set docimage to item linknumber of linkList

        tell application "Finder"

        set aName to name of file docimage

        end tell

        tell application "Finder"

        try

        copy file docimage to folder picfolder

        end try

        end tell

        end repeat

        end tell

        convertpics(picfolder) of me

        end tell

      end movePics

       

      on convertpics()

        tell application "Finder" to set origimages to files of entire contents of folder picfolder

        repeat with i in origimages

        set oneImage to i as string

        tell application "Adobe Photoshop CS6"

        open file oneImage

        change mode of current document to grayscale

        set fullname to name of current document as string

        try

        set AppleScript's text item delimiters to {"_"}

        set bwname to second text item of fullname

        end try

        if bwname ≠ "BW.TIF" then

        set AppleScript's text item delimiters to {"."}

        set fname to first text item of fullname

        set myFile to picfolder & fname & "_BW"

        save current document in file myFile as TIFF -- with options {byte order:Mac OS, embed color profile:false, image compression:LZW, save alpha channels:false, save layers:false, transparency:true} appending lowercase extension

       

        end if

        close document 1 without saving

        end tell

        end repeat

        indesignRelink()

      end convertpics

       

      on indesignRelink()

        repeat with i in origimages

        set oneImage to i as string

        tell application "Finder"

        set fname to name of file oneImage

        end tell

        tell application "Adobe InDesign CS6"

        set origlink to picfolder & fname

        set AppleScript's text item delimiters to {"."}

        set justname to first text item of fname

        set newpick to picfolder & justname & "_BW.TIF"

        display dialog newpick

        relink origlink to newpick

        end tell

        end repeat

      end indesignRelink

        • 1. Re: relink problem
          greenrookie Level 2

          Hi JonnyDL,

           

          I haven't gone through all the code and I presume that the other parts work and that you're stuck on the relinking at the end.


          Try this.

           

          On the 'on convertpics()' handler block:

           

          Change indesignRelink() to:

           

          my indesignRelink()

           

           

          On the 'on indesignRelink()' handler block:

           

                    set newpick to picfolder & justname & "_BW.TIF" as string

                    display dialog newpick

                  relink origlink to alias newpick

           

           

           

          greenrookie

          • 2. Re: relink problem
            JonnyDL Level 1

            greenrookie

            sorry for the slow response got tied up in other things. that didn't seem to work.

             

            I get  a very indescriptive  error. that it doesn't understand the relink command. I've tried caring combinations of the relink command, and I keeps giving me the same error. I'm thinking it is how the relink command is seeing the path (as not a acceptable path format?). I'll try and find some working relink code, and see if i can find were mine is gone wrong. Any suggestions otherwise would be appreciated.

            • 3. Re: relink problem
              greenrookie Level 2

              Right.

               

              We don't need to to loop in the Finder, we loop with try in InDesign, and InDesign will take care of the link for us (nice).

               

              I tested it for me, let me know how you get on.

               

              Replace the whole block.

               

               

              on indesignRelink()

                            tell application "Adobe InDesign CS6"

                                           tell active document

                                                         set evGraphic to every link

                                                         repeat with i from 1 to count of evGraphic

                                                                        try

                                                                                      set origlink to item i of evGraphic

                                                                                      set fname to name of origlink

                                                                                      set AppleScript's text item delimiters to {"."}

                                                                                      set justname to first text item of fname

                                                                                      set newpick to picfolder & justname & "_BW.TIF" as string

                                                                                      --display dialog newpick

                                                                                      relink origlink to alias newpick

                                                                        end try

                                                         end repeat

                                           end tell

                            end tell

              end indesignRelink