Skip to main content
Gibson Editions
Inspiring
June 14, 2021
Answered

BridgeTalk with menu item and calling a photoshop script.

  • June 14, 2021
  • 4 replies
  • 2020 views

I have quite a few scripts that i use to process multiple files. I would like to be able to call them from bridge in order to call  selected thumbnails from multiple bridge documents. 

 

I have the basis modified from  @DBarranca code  but im new to bridgetalk and not certain how the structure works.

 

How do i call this from a bridge menu item???

 

How/ where do a reference an external photoshop script that id like to call to run on these open files??

 

//from Davide Barrancas code


#target photoshop


if (BridgeTalk.isRunning('bridge')) {
  var bt = new BridgeTalk();
  bt.target = "bridge";
  bt.body = "" + getSelectedFilesPath.toString() + "; getSelectedFilesPath();";
  bt.onResult = function(response) {
    var filesArray = eval(response.body);
    for (var i = 0; i < filesArray.length; i++) {
      app.open(new File(filesArray[i]))
    }

  }
  bt.onError = function(err) {
    alert("Error!\n" + err.body)
  }
  bt.send(20);
  alert("Done")
}

// Bridge function
function getSelectedFilesPath() {
  var filesArray = [];
   for (var m = 0; m <= app.documents.length - 1; m++){
  for (var i = 0; i <= app.documents[m].selections.length - 1; i++) {
    if (app.documents[m].selections[i].type == "file") {
      filesArray.push(app.documents[m].selections[i].path);
    }
  }
}
  return filesArray.toSource();
}

 

 

This topic has been closed for replies.
Correct answer Gibson Editions

This is my final script... 

It's the first time i've used bridgetalk, so was interesting to start to understand the syntax, passing infomation to the target application via the body as a string.  I have added some comments to make it a little more useful to anyone who sees it. 

 



//CREATE A MENU ITEM IN BRIDGE
var runjsx = MenuElement.create("command", "runJSX", "at the end of Tools");
  
  
  
  //MAIN FUNCTION 
  runjsx.onSelect = function () {

//RUNNING IN BRIDGE
      filesArray = eval(getSelectedFilesPath())

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

//SWITCHING TO PHOTOSHOP
		bt = new BridgeTalk();
        bt.target = 'photoshop';
        bt.body =  'app.open(new File("' + filesArray[i] + '"))'
        bt.send();

}


//RUNNING IN PHOTOSHOP TO RUN SCRIPT ON ALL OPEN FILES.... 
	bt1 = new BridgeTalk();
        bt1.target = 'photoshop';
        bt1.body = script.toString() + "; script();" ;
        bt1.send();


}





//FUNCTIONS 
function getSelectedFilesPath() {
var filesArray = [];
   for (var m = 0; m <= app.documents.length - 1; m++){
  for (var i = 0; i <= app.documents[m].selections.length - 1; i++) {
    if (app.documents[m].selections[i].type == "file") {
      filesArray.push(app.documents[m].selections[i].path);
    }
  }
}
  return filesArray.toSource();
}



//CALLING EXTERNAL SCRIPT
function script(){
    /*amend with your script name*/
var scriptName = "test.jsx"; 
var f = File(app.path + "/presets/scripts/Lyr/" + scriptName);
$.evalFile(f);
}

 

 

 

4 replies

Gibson Editions
Gibson EditionsAuthorCorrect answer
Inspiring
June 15, 2021

This is my final script... 

It's the first time i've used bridgetalk, so was interesting to start to understand the syntax, passing infomation to the target application via the body as a string.  I have added some comments to make it a little more useful to anyone who sees it. 

 



//CREATE A MENU ITEM IN BRIDGE
var runjsx = MenuElement.create("command", "runJSX", "at the end of Tools");
  
  
  
  //MAIN FUNCTION 
  runjsx.onSelect = function () {

//RUNNING IN BRIDGE
      filesArray = eval(getSelectedFilesPath())

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

//SWITCHING TO PHOTOSHOP
		bt = new BridgeTalk();
        bt.target = 'photoshop';
        bt.body =  'app.open(new File("' + filesArray[i] + '"))'
        bt.send();

}


//RUNNING IN PHOTOSHOP TO RUN SCRIPT ON ALL OPEN FILES.... 
	bt1 = new BridgeTalk();
        bt1.target = 'photoshop';
        bt1.body = script.toString() + "; script();" ;
        bt1.send();


}





//FUNCTIONS 
function getSelectedFilesPath() {
var filesArray = [];
   for (var m = 0; m <= app.documents.length - 1; m++){
  for (var i = 0; i <= app.documents[m].selections.length - 1; i++) {
    if (app.documents[m].selections[i].type == "file") {
      filesArray.push(app.documents[m].selections[i].path);
    }
  }
}
  return filesArray.toSource();
}



//CALLING EXTERNAL SCRIPT
function script(){
    /*amend with your script name*/
var scriptName = "test.jsx"; 
var f = File(app.path + "/presets/scripts/Lyr/" + scriptName);
$.evalFile(f);
}

 

 

 

Gibson Editions
Inspiring
June 15, 2021

and it requires a pause in between opening and running script as per @Kukurykus script 

 

$.sleep(500);

 

Brainiac
June 15, 2021

Tools->Photoshop->Batch

Its built-in.

Gibson Editions
Inspiring
June 15, 2021

Cheers im aware of that but, it doesnt work across multiple bridge windows

Gibson Editions
Inspiring
June 14, 2021

So let me show a bit more of my bodged together code, which is not currently functioning in bridge...

 

I want to run this script as a menu item from Bridge

-get selected files from bridge

-open them in photoshop

-run a photoshop script on the opened files

 

My queries are:

-should be setting photoshop or bridge as the initial target of the script

- do i need one bridgetalk instance to get the files and another to run the photoshop opening and script part

 

 

@SuperMerlin I have tried to use some of your code but failed... 

 

 

#target photoshop

if (BridgeTalk.isRunning('bridge')) {
    runjsx = MenuElement.create("command", "add Layout", "at the end of Tools");
  
  runjsx.onSelect = function () {
  var bt = new BridgeTalk();
  bt.target = "bridge";
  bt.body = "" + getSelectedFilesPath.toString() + "; getSelectedFilesPath();";
  bt.onResult = function(response) {
    var filesArray = eval(response.body);
    for (var i = 0; i < filesArray.length; i++) {
      app.open(new File(filesArray[i]))
      script()
    }

  }
  bt.onError = function(err) {
    alert("Error!\n" + err.body)
  }
  bt.send(20);
  alert("Done")
}}

// Bridge function
function getSelectedFilesPath() {
  var filesArray = [];
   for (var m = 0; m <= app.documents.length - 1; m++){
  for (var i = 0; i <= app.documents[m].selections.length - 1; i++) {
    if (app.documents[m].selections[i].type == "file") {
      filesArray.push(app.documents[m].selections[i].path);
    }
  }
}
  return filesArray.toSource();
}



function script(){
    /*amend with your script name*/
var scriptName = "test.jsx"; 
var f = File(app.path + "/presets/scripts/Lyr/" + scriptName);
$.evalFile(f);
}

 

Kukurykus
Brainiac
June 14, 2021

I already gave you a script you can easily edit, so change alert part to photoshop function that opens files from array sent from Bridge. If you don't know how to use it I am giving you something easier:

 

slctdThmbnls = new MenuElement('command',
'Thumbnails', 'at the end of Tools')
				
slctdThmbnls.onSelect = function() {
	if ((ad = app.document).selectionLength) {
		ad.chooseMenuItem('Open'), $.sleep(500)
		function ps() {alert('Photoshop Script')}
		(bt = new BridgeTalk()).target = 'photoshop',
		bt.body = 'ps = ' + ps.toSource() + ', ps()', bt.send()
	}
}

 

Gibson Editions
Inspiring
June 14, 2021

Ah i see, I'll let you know how i get on. 

Kukurykus
Brainiac
June 14, 2021

Moderator, if you read it, please move this thread to Bridge and add to it 'scripting' label.

 

Right mouse click at selected thumnbail(s) and look for the command at bottom of menu:

 

slctdThmbnls = new MenuElement('command',
'Thumbnails', 'at the end of Thumbnail')
				
slctdThmbnls.onSelect = function() {
	slctns = app.document.selections; for(i in slctns) {
		if ((itm = slctns[i]).type == 'file') slctns[i] = itm.spec
	}
	if (slctns.length)
		(bt = new BridgeTalk()).target = 'photoshop',
		bt.body = 'alert(' + slctns.toSource() + ')', bt.send()
}

 

jane-e
Community Expert
June 14, 2021

@Kukurykus wrote:

Moderator, if you read it, please move this thread to Bridge and add to it 'scripting' label.

 

Do you know how to get moderator privileges, @Kukurykus ? PM me if you don't know how.

 

~ Jane

jane-e
Community Expert
June 14, 2021


@Kukurykus wrote:

Moderator, if you read it, please move this thread to Bridge and add to it 'scripting' label.

 

Do you know how to get moderator privileges, @Kukurykus ? PM me if you don't know how.

~ Jane


 

Moved to Adobe Bridge from Adobe Photoshop at the request of @Kukurykus . Scripting label added.

 

~ Jane