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

Select Bridge thumbnails run custom Photoshop script

Engaged ,
May 02, 2018 May 02, 2018

Working with high image volume. Use a photoshop script to create derivative files from the master PSD file in Photoshop. Like to be able to select the PSD files in Bridge and run the Photoshop script from Bridge.  Is there a method or function to select thumbnails in Bridge and to run a Photoshop script?

Environment

Bridge CC 2018

Photoshop CC 2018

OSX High Sierra

TOPICS
Actions and scripting
2.4K
Translate
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

Guide , May 06, 2018 May 06, 2018

Hope this helps...

#target photoshop;

app.bringToFront();

main();

function main(){

//get an array of files from Bridge

var files = GetFilesFromBridge();

//get output folder

outputFolder = Folder.selectDialog("Please select Output folder");

if(outputFolder == null ) return;

//iterate through Bridge files

for(var a in files){

//open each file in turn

app.open(files);

//get the filename without extension

var Name = files.name.replace(/\.[^\.]+$/, '');

//create new filename

var saveFile = File(outputFolder +"/" +Nam

...
Translate
Adobe
Guide ,
May 03, 2018 May 03, 2018

In Bridge use $.evalFile(); to execute your Photoshop script, in your Photoshop script get the selected files.

function getFilesFromBridge(){

var fileList =[];

var bt = new BridgeTalk();

bt.target = "bridge";

bt.body = "var F = photoshop.getBridgeFileListForAutomateCommand();F.toSource();";

bt.onResult = function( inBT ) { fileList = eval( inBT.body ); }

bt.onError = function( inBT ) { fileList = new Array(); }

bt.send(8);

return fileList;

};

Translate
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
Engaged ,
May 05, 2018 May 05, 2018

I have basic scripting knowledge. Is there sample Bridge script which calls a photoshop script after a thumbnail is selected in Bridge?  I have installed my custom Bridge script and can access it through the menu, but the Photoshop script does not execute when run from bridge.

Translate
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
Guide ,
May 05, 2018 May 05, 2018

Once you have selected you files you can use this script to call the Photoshop script.

N.B. The Photoshop script must get the selected files as in the above example.

Amend the scriptName variable to your Photoshop script name.

#target bridge  

   if( BridgeTalk.appName == "bridge" ) { 

runjsx = MenuElement.create("command", "Run Photoshop JSX", "at the end of Tools");

}

runjsx .onSelect  = function () {

function script(){

    /*amend with your script name*/

var scriptName = "Your File Name.jsx";

var f = File(app.path + "/presets/scripts/" + scriptName);

$.evalFile(f);

}

var bt = new BridgeTalk;

bt.target = "photoshop";

bt.body = " ftn = " + script.toSource() + "; ftn();";

bt.send(8);

};

Translate
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
Engaged ,
May 05, 2018 May 05, 2018

Thank you for your help SuperMerlin, the code does work. I understand the Photoshop script needs to get the selected files from Bridge. I have placed the function getFilesFromBridge() in the Photoshop script. I am not sure where and how call this function in the Photoshop script. For instance the PS script saves a jpg file with folder selection: Where should I put the function call?

// save to a folder using a dialog box

var theFolder = Folder.selectDialog ("Select Folder");

if (theFolder) {

        var myFile = new File( theFolder + "/" + app.activeDocument.name); 

        app.activeDocument.saveAs(myFile, jpgOptions, true);

    }

//close all documents without saving changes to original

while(documents.length>0){ 

        documents[documents.length-1].close(SaveOptions.DONOTSAVECHANGES);

    }

// jpeg save file options

var jpgOptions = new JPEGSaveOptions();

jpgOptions.embedColorProfile = true;

jpgOptions.alphaChannels = true;

jpgOptions.layers = true;

jpgOptions.spotColors = true;

// get selected files from Bridge

function getFilesFromBridge(){ 

    var fileList =[]; 

    var bt = new BridgeTalk(); 

    bt.target = "bridge"; 

    bt.body = "var F = photoshop.getBridgeFileListForAutomateCommand();F.toSource();"; 

    bt.onResult = function( inBT ) { fileList = eval( inBT.body ); } 

    bt.onError = function( inBT ) { fileList = new Array(); } 

    bt.send(8); 

    return fileList; 

};

Translate
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
Guide ,
May 06, 2018 May 06, 2018

Hope this helps...

#target photoshop;

app.bringToFront();

main();

function main(){

//get an array of files from Bridge

var files = GetFilesFromBridge();

//get output folder

outputFolder = Folder.selectDialog("Please select Output folder");

if(outputFolder == null ) return;

//iterate through Bridge files

for(var a in files){

//open each file in turn

app.open(files);

//get the filename without extension

var Name = files.name.replace(/\.[^\.]+$/, '');

//create new filename

var saveFile = File(outputFolder +"/" +Name + ".jpg");

//save file

SaveJPEG(saveFile,8);

//close document

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

}//end files

}

//FUNCTIONS

function GetFilesFromBridge() {

    var fileList=[];

    if ( BridgeTalk.isRunning( "bridge" ) ) {

        var bt = new BridgeTalk();

        bt.target = "bridge";

        bt.body = "var theFiles = photoshop.getBridgeFileListForAutomateCommand();theFiles.toSource();";

        bt.onResult = function( inBT ) { fileList = eval( inBT.body ); }

        bt.onError = function( inBT ) { fileList = new Array(); }

        bt.send(8);

    }

    return fileList;

};

function SaveJPEG(saveFile, jpegQuality){

jpgSaveOptions = new JPEGSaveOptions();

jpgSaveOptions.embedColorProfile = true;

jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;

jpgSaveOptions.matte = MatteType.NONE;

jpgSaveOptions.quality = jpegQuality;

activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);

};

Translate
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
Engaged ,
May 06, 2018 May 06, 2018
LATEST

Thank you SuperMerlin the script works great! I appreciate your comments on the script, it makes easy to follow the logic.

Translate
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