Skip to main content
bastieneichenberger
Inspiring
September 18, 2013
Question

problem CS5 - CS6, link.filePath

  • September 18, 2013
  • 0 replies
  • 419 views

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

try{

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

        alert(has_item_alpha_channel (array_links_item) );

    }

}

catch(ex){

    alert(ex.message);

}

/**

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

* @9397041 {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;

    }

    else{

        res = false;

    }

    return res;

}

function replaceAll(find, replace, str) {

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

}

This topic has been closed for replies.