• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

call bridge from other app

Explorer ,
Aug 20, 2013 Aug 20, 2013

Copy link to clipboard

Copied

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 );

};

TOPICS
Scripting

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Aug 20, 2013 Aug 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…

Votes

Translate

Translate
Explorer ,
Aug 20, 2013 Aug 20, 2013

Copy link to clipboard

Copied

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;

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 20, 2013 Aug 20, 2013

Copy link to clipboard

Copied

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;

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Aug 20, 2013 Aug 20, 2013

Copy link to clipboard

Copied

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…

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 20, 2013 Aug 20, 2013

Copy link to clipboard

Copied

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);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Aug 20, 2013 Aug 20, 2013

Copy link to clipboard

Copied

As I came from AppleScript background before moving to ExtendScript…

Im in the habit of single quoting in ESTK so it's less escaping when mixing the two.

Shell likes escaped or properly quoted strings so it can sometimes be a little tricky when passing back and forth.

The above snippet will write the result to the desktop… and you will need to read this you can actually set a variable to your AppleScript call and return the result directly to your ExtendScript.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 21, 2013 Aug 21, 2013

Copy link to clipboard

Copied

Hi,

Thanks for your help, it was a good idea:)

I will use simple quote for the next time but my all script use double so … I will change for the next one!

My code look like this and works:

#target indesign

function is_item_transparent(){

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

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

    alert(result);

}

But now I have an other problem with the path of the link that I become from indesign:

set result to do shell script "sips -g hasAlpha 'Macintosh HD/Users/bastieneichenberger/Desktop/Capture d’écran 2013-08-21 à 08.47.27.png'"

In fact the path contains "Macintosh HD" and the terminal said that it isn't a valid file path.

#target indesign

var doc = app.activeDocument;

var array_all_links = doc.links;

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

    alert(is_item_transparent (array_all_links) );

}

function is_item_transparent(link_item){

    // replace all : -> /

    // resolve problem path with Macintosh HD

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

    alert(appleScript);

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

    alert(result);

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

    if(res != null){

        res = true;

    }

    else{

        res = false;

    }

    return res;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 21, 2013 Aug 21, 2013

Copy link to clipboard

Copied

LATEST

Hi all,

If it can be helpfull for someone. This function return true if a link in indesign contains an alpha channel.

#target indesign

var doc = app.activeDocument;

var array_all_links = doc.links;

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

    alert(is_item_transparent (array_all_links) );

}

function is_item_transparent(link_item){

    // 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);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines