0 Replies Latest reply on Sep 18, 2013 2:52 AM by bastieneichenberger

    problem CS5 - CS6, link.filePath

    bastieneichenberger Level 1

      Hi all,


      I wrote a script who works on max os x and CS6, CS5.5 version.

      But this same script doesn't work on CS5 and I don't know why.


      I think it's maybe because the filePath isn't not the same. It's maybe an encoding probem Not the first time for me!


      Can someone help me?


      #target indesign



      var my_doc = app.activeDocument;

      var array_links_item = my_doc.links;



      // get all links


          for(var i=0; i < array_links_item.length; i++){

              alert(has_item_alpha_channel (array_links_item[i]) );















      * function to check if an image contains alpha channel, this function run an AppleScript to call the shell (sips -g hasAlpha function)

      * @param {Link} link_item

      * @return {Boolean} true if the image contains an alpha channel

      * @throws {Error} if the system is windows, the function works only on mac os x


      function has_item_alpha_channel(link_item){

          if(File.fs == "Windows"){

              throw new Error("the function has_alpha_channel works only on mac os x");


          // replace all : to /

          var file_path = replaceAll (":", "/", link_item.filePath);

          // remove Macintosh HD from path   

          file_path = file_path.replace("Macintosh HD", "");



          var appleScript = "set result to do shell script \"sips -g hasAlpha '"+  file_path +"'\"";

          var result = app.doScript(appleScript, ScriptLanguage.applescriptLanguage);

          var res = result.match("hasAlpha: yes");

          if(res != null){

              res = true;



              res = false;


          return res;




      function replaceAll(find, replace, str) {

        return str.replace(new RegExp(find, 'g'), replace);