7 Replies Latest reply on Oct 10, 2014 12:34 AM by greenrookie

    AppleScript - Get links from one layer

    FredrikM

      I need to make a list of linked files from one InDesign layer only but can't figure out how.

       

      This is my base that works just fine but gives me a list of all linked files in my document.

      set layFilesLinksList to every link of document 1

       

      I have tried this

      set linksList to every link of document 1 whose active layer is "Images"

      set linksList to every link of layer "Images" of document 1

       

      Any other suggestions?

        • 1. Re: AppleScript - Get links from one layer
          BEGINNER_X Level 3

          Hi FredrikM,

           

          May the below code is useful:

           

          var myLinks = app.activeDocument.links;
          
          alert(myLinks.length);
          
          totalLinks = new Array();
          
          
          for(i=0; i<myLinks.length; i++)
          {
              if(myLinks[i].parent.itemLayer.name == "Layer 1")
              {
                  if(myLinks[i].status == LinkStatus.NORMAL)
                  {
                      alert(myLinks[i].name)
                      totalLinks.push(myLinks[i].name + "\r")
                      }
                  }
              }
          
          alert("totalLinks")
          

           

           

          Regards

          Siraj

          • 2. Re: AppleScript - Get links from one layer
            greenrookie Level 2

            In Applescript.

             

            tell application "Adobe InDesign CS5.5"

                tell active document

                    if exists layer "Images" then set layerImages to layer "Images"

                    set grphicBoxs to all graphics of layerImages

                    set myLinks to {}

                    repeat with i in grphicBoxs

                        set iLink to item link of i

                        set pathLink to file path of iLink

                        set end of myLinks to pathLink

                    end repeat

                    return myLinks

                end tell

            end tell

             

            Greenrookie

            • 3. Re: AppleScript - Get links from one layer
              FredrikM Level 1

              Thanks for the reply Siraj, the code you pasted does not seem to be AppleScript code though and i'm not capable to translate this code into AppleScript.

              • 4. Re: AppleScript - Get links from one layer
                FredrikM Level 1

                Thanks!

                 

                We are a bit on the way, if i run your script as stand alone i get one of many images in the layer "Images"

                But when implementing this code in my bigger script i get nothing.

                 

                This works as before, i get every link in my document.

                 

                on createMiniature()

                 

                  tell application "Adobe InDesign CS5"

                  set user interaction level of script preferences to never interact

                  activate

                  set myLinks to every link of document 1

                 

                  (*

                  -- Images from one layer only workaround --

                  tell active document

                 

                  if exists layer "Images" then set layerImages to layer "Images"

                  set grphicBoxs to all graphics of layerImages

                  set myLinks to {}

                  repeat with i in grphicBoxs

                  set iLink to item link of i

                  set pathLink to file path of iLink

                  set end of myLinks to pathLink

                 

                  end repeat

                  return myLinks

                  end tell

                 

                  -- End Images from one layer only workaround --

                  *)

                  repeat with thisFile in myLinks

                 

                  set ruler origin of view preferences of document 1 to spread origin

                  set zero point of document 1 to {0, 0}

                  set zeroX to 0

                  set zeroY to ((page height of document preferences of document 1) + 5)

                  set pageHeight to ((page height of document preferences of document 1))

                  set pageWidth to ((page width of document preferences of document 1))

                  set maxHeight to 13

                  set theScale to maxHeight / pageHeight

                  set imageXPos to ((item 2 of geometric bounds of parent of parent of thisFile))

                  set imageYPos to ((item 1 of geometric bounds of parent of parent of thisFile))

                  set imageXPos2 to ((item 4 of geometric bounds of parent of parent of thisFile))

                  set imageYPos2 to ((item 3 of geometric bounds of parent of parent of thisFile))

                  set imageWidth to imageXPos2 - imageXPos

                  set imageHeight to imageYPos2 - imageYPos

                  set theName to name of thisFile

                  set filePath to ((file path of thisFile))

                  set theImgPath to quoted form of POSIX path of filePath

                  set imageStatus to ""

                  set imageStatus to do shell script ("/usr/bin/exiftool -xmp:Instructions -b " & theImgPath)

                 

                  if imageStatus = "" then

                  set imageStatus to "Paper"

                  end if

                 

                  set newBox to (make new rectangle of document 1 with properties {geometric bounds:{zeroY + imageYPos * theScale, zeroX + imageXPos * theScale, (zeroY + (imageYPos + imageHeight) * theScale), zeroX + (imageXPos + imageWidth) * theScale}, stroke weight:0.2, stroke color:"Black", fill color:imageStatus, active layer:StatusLayer})

                  set opacity of blending settings of fill transparency settings of newBox to 60

                 

                 

                  end repeat

                  set the properties of layer StatusLayer of document 1 to {visible:false}

                  end tell

                end createMiniature

                 

                Changing the script to this gives me a blank result with no images

                 

                on createMiniature()

                 

                  tell application "Adobe InDesign CS5"

                  set user interaction level of script preferences to never interact

                  --activate

                  --set myLinks to every link of document 1

                 

                  -- Images from one layer only workaround --

                  tell active document

                 

                  if exists layer "Images" then set layerImages to layer "Images"

                  set grphicBoxs to all graphics of layerImages

                  set myLinks to {}

                  repeat with i in grphicBoxs

                  set iLink to item link of i

                  set pathLink to file path of iLink

                  set end of myLinks to pathLink

                 

                  end repeat

                  return myLinks

                  end tell

                 

                  -- End Images from one layer only workaround --

                 

                  repeat with thisFile in myLinks

                 

                  set ruler origin of view preferences of document 1 to spread origin

                  set zero point of document 1 to {0, 0}

                  set zeroX to 0

                  set zeroY to ((page height of document preferences of document 1) + 5)

                  set pageHeight to ((page height of document preferences of document 1))

                  set pageWidth to ((page width of document preferences of document 1))

                  set maxHeight to 13

                  set theScale to maxHeight / pageHeight

                  set imageXPos to ((item 2 of geometric bounds of parent of parent of thisFile))

                  set imageYPos to ((item 1 of geometric bounds of parent of parent of thisFile))

                  set imageXPos2 to ((item 4 of geometric bounds of parent of parent of thisFile))

                  set imageYPos2 to ((item 3 of geometric bounds of parent of parent of thisFile))

                  set imageWidth to imageXPos2 - imageXPos

                  set imageHeight to imageYPos2 - imageYPos

                  set theName to name of thisFile

                  set filePath to ((file path of thisFile))

                  set theImgPath to quoted form of POSIX path of filePath

                  set imageStatus to ""

                  set imageStatus to do shell script ("/usr/bin/exiftool -xmp:Instructions -b " & theImgPath)

                 

                  if imageStatus = "" then

                  set imageStatus to "Paper"

                  end if

                 

                  set newBox to (make new rectangle of document 1 with properties {geometric bounds:{zeroY + imageYPos * theScale, zeroX + imageXPos * theScale, (zeroY + (imageYPos + imageHeight) * theScale), zeroX + (imageXPos + imageWidth) * theScale}, stroke weight:0.2, stroke color:"Black", fill color:imageStatus, active layer:StatusLayer})

                  set opacity of blending settings of fill transparency settings of newBox to 60

                 

                 

                  end repeat

                  set the properties of layer StatusLayer of document 1 to {visible:false}

                  end tell

                end createMiniature

                • 5. Re: AppleScript - Get links from one layer
                  greenrookie Level 2

                  Hi FredrikM,

                   

                  I haven't tried your script, try replace this section with this.

                   

                  -- Images from one layer only workaround --

                   

                    tell active document

                    if exists layer "Images" then set layerImages to layer "Images"

                    try

                    set grphicBoxs to all graphics of layerImages

                    set myLinks to {}

                    repeat with i in grphicBoxs

                    set iLink to item link of i

                    set end of myLinks to iLink

                    end repeat

                    end try

                    end tell

                   

                    -- End Images from one layer only workaround --

                  • 6. Re: AppleScript - Get links from one layer
                    FredrikM Level 1

                    Thankyou very much, just a little tweak and it works!

                     

                      -- Images from one layer only workaround --

                      tell active document

                     

                      if exists layer "Images" then set layerImages to layer "Images"

                      set grphicBoxs to all graphics of layerImages

                      set myLinks to {}

                      repeat with i in grphicBoxs

                      set iLink to item link of i

                      set end of myLinks to iLink

                      end repeat

                     

                      end tell

                     

                      -- End Images from one layer only workaround --

                    • 7. Re: AppleScript - Get links from one layer
                      greenrookie Level 2

                      You're welcome FredrikM.

                       

                      I thought at first that you just wanted to collect the names or file paths of the links, so the initial code was to return a list of these items.

                       

                      When you posted the code, then I understood what you were trying to do.

                       

                      Best,

                      GreenRookie