Skip to main content
bastieneichenberger
Inspiring
August 20, 2013
Answered

call bridge from other app

  • August 20, 2013
  • 2 replies
  • 1755 views

Hi all,

I developpe a script who need to call the terminal to execute a command line.

For that, is think i will call bridge from indesign and use the command app.system(shell_str);.

But i don't know how to get a bridge app from an indesign script?

sample:

#target indesign

var doc = app.activeDocument;

var array_all_links = doc.links;

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

    is_transparency (array_all_links);

}

function is_transparency(link_item) {

         

          var shellString = "mdfind -onlyin ";

 

          shellString += "'" + link_item.filePath + "/'";

 

          shellString += " 'kMDItemHasAlphaChannel == 1 ";

 

          shellString += " && (kMDItemFSName == *.tif || kMDItemFSName == *.psd || kMDItemFSName == *.png)' > ";

 

          shellString += "~/Desktop/StdOut.txt";

         

          //call bridge

          var targetApp = BridgeTalk.getSpecifier( "bridge", "1");

          var sh = targetApp.system( shellString );

          // error

          return( sh );

};

This topic has been closed for replies.
Correct answer Muppet Mark

You do NOT need BridgeTalk or Bridge the app to do this… Those examples you found call the system shell…

In Indesign you can have Applescript call do shell script this way will avoid opening Bridge if it is not already running…

2 replies

bastieneichenberger
Inspiring
August 20, 2013

Hi,

If it can be helpfull for someone the probem was the quote:

#target indesign

var doc = app.activeDocument;

var array_all_links = doc.links;

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

    is_transparent (array_all_links);

}

function is_transparent(link_item){

    var bt = new BridgeTalk;

          bt.target = "bridge";

    var shell_str = get_shell_str (link_item);

    var myScript = "app.system('"+ shell_str +"');";

    alert(myScript);

    bt.body = myScript;

    bt.send();

}

function get_shell_str(link_item) {

          var shellString = "sips -g hasAlpha /Users/bastieneichenberger/Desktop/test2.png > ~/Desktop/result.txt";

         

          // var shellString = "sips -g hasAlpha "+ link_item.filePath +" > ~/Desktop/result.txt";

         

          return shellString;

};

Muppet MarkCorrect answer
Inspiring
August 20, 2013

You do NOT need BridgeTalk or Bridge the app to do this… Those examples you found call the system shell…

In Indesign you can have Applescript call do shell script this way will avoid opening Bridge if it is not already running…

bastieneichenberger
Inspiring
August 20, 2013

Hi,

Thanks your for your answer its nice from you.

I do something like this but i become an error.

I already tested my appleScript and he works.

var appleScript = "do shell script \"sips -g hasAlpha /Users/bastieneichenberger/Desktop/test2.png\" > ~/Desktop/result.txt";

var parameter = null;

app.doScript(appleScript, ScriptLanguage.applescriptLanguage, parameter);

bastieneichenberger
Inspiring
August 20, 2013

Hi all,

I finally found a solution to call bridge and use a shell function…

But now I have this problem: the shell function always return 0 and I would like that the shell function return the shell result.

Has someone an idea how to read the result of a shell function in a script?

#target indesign

var doc = app.activeDocument;

var array_all_links = doc.links;

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

    is_transparent (array_all_links);

}

function is_transparent(link_item){

    var bt = new BridgeTalk;

          bt.target = "bridge";

    var myScript = "app.system(";

    myScript += shell_str(link_item);

    myScript += ");";

    alert(myScript);

    bt.body = myScript;

    // the var result containt always 0, it is the execution code report and I would have the result of this shell function

    var result = bt.send();

    alert(result);

}

// this function is ok and return hasAlphaChannel: yes

function shell_str(link_item) {

          var shellString = "sips -g hasAlpha /Users/bastieneichenberger/Desktop/test.png";

          return shellString;

};