Bridge Export Panel Sample Code

  • 2
  • Idea
  • Updated 9 months ago
  • (Edited)
I've seen complaints about the Export Panel being removed from Bridge. There is still export to JPEG functionality exposed via JavaScript in Bridge CC.

I did some noodling around with ExtendScript Toolkit and Adobe sample code and wrote a JPEG export palette. It runs as a script which can be invoked from the Tools menu.

Save the code below as a ".jsx" file and move it into the Bridge Startup Scripts folder (Preferences->Startup Scripts->Reveal My Startup Scripts).

The loaded palette looks like:



Caveats:

1. This is based on Adobe sample code and snippets found online. I claim no copyright in any of it.
2. This is provided as-is, where is. It is not bullet-proof or probably even spitball-proof.
3. Please do not contact me to add/fix/maintain this code. You are welcome to modify it yourself. 
4. Leave "Long Dimension" blank to keep original size.
5. Metadata is not preserved.
6. You'll need to fix line wrapping due to this forum reformatting it.
7. Tested with Bridge CC 2018. I suspect it will work as far back as CS6 due to that being the SDK version.
8. For Windows systems, change "var exportFilePath = thumbs[i].parent.spec + "/" + repname + "_new.jpg";" to "var exportFilePath = thumbs[i].parent.spec + "\\" + repname + "_new.jpg";" so the path separator is correct.

////////////////////////////////////////////////////////////////////////////
// ADOBE SYSTEMS INCORPORATED
// Copyright 2008 Adobe Systems Incorporated
// All Rights Reserved
//
// NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance with the
// terms of the Adobe license agreement accompanying it.  If you have received this file from a
// source other than Adobe, then your use, modification, or distribution of it requires the prior
// written permission of Adobe.
/////////////////////////////////////////////////////////////////////////////

 

if(BridgeTalk.appName == "bridge")

var newCommand = new MenuElement("command", "JPEG Export Palette", "at the end of Tools");
}
newCommand.onSelect = function ()
{
JPEGPalette();
}
function JPEGPalette()
{
this.paletteRefs = new Array();
var wrapper = this;
function addScriptPalette(doc)
{
var scriptPalette = new TabbedPalette(doc, "JPEG Export", "JPEGPalette", "script");
wrapper.paletteRefs.push(scriptPalette);
scriptPalette.content.add('statictext', [25,15,225,100],'Select at least one PSD, JPG,\rPNG, TIFF, or GIF file to convert.\r\rAdjust settings and click Save.',{multiline:true});
var tbPanel = scriptPalette.content.add('panel', [25,100,250,325], 'JPEG Settings');
tbPanel.txtFieldLbl = tbPanel.add('statictext', [15,15,105,35], 'Quality (1-100):');
tbPanel.txt1 = tbPanel.add('statictext', [115,15,165,35],'80');
tbPanel.slider1 = tbPanel.add('slider', [15,30,125,55]);
tbPanel.slider1.minvalue = "1";
tbPanel.slider1.value = "80";
tbPanel.txtField2Lbl = tbPanel.add('statictext', [15,75,145,95], 'Long Dimension (px):');
tbPanel.txt2=tbPanel.add('edittext', [155,77,185,92], '');
tbPanel.txtField2Lbl = tbPanel.add('statictext', [15,120,140,150], 'Preserve Colorspace');
tbPanel.cb1=tbPanel.add('checkbox',[155,122,171,138]);
tbPanel.cb1.value = true;
tbPanel.addBtn = tbPanel.add('button', [10,185,120,205], 'Save As JPEG');
tbPanel.txt2.graphics.backgroundColor = tbPanel.txt2.graphics.newBrush (tbPanel.txt2.graphics.BrushType.SOLID_COLOR, [.5, .5, .5]);        
tbPanel.txt1.onChange = function()
{
tbPanel.slider1.value = tbPanel.txt1.text;
}
tbPanel.slider1.onChanging = function()
{
tbPanel.txt1.text = Math.round(tbPanel.slider1.value);
}
tbPanel.txt2.onChanging = function()
{
if((parseFloat(tbPanel.txt2.text) == parseInt(tbPanel.txt2.text)) && !isNaN(tbPanel.txt2.text))
{
if(tpPanel.txt2.text > "8192" || tpPanel.txt2.text < "0")
{
tbPanel.txt2.text = "";
}
}
else
{
tbPanel.txt2.text = "";
}
}
tbPanel.addBtn.onClick = function()
{
var thumbs = app.document.getSelection("psd, jpg, png, tif, gif");
if(thumbs.length != 0)
{
for(var i = 0;i < thumbs.length;i++)
{
if(thumbs[i].spec instanceof File)
{
var thumb = thumbs[i];
var colorspace = tbPanel.cb1.value;
var bm = new BitmapData(thumbs[i].spec, colorspace);
if(bm instanceof BitmapData)
{
var fullName = thumbs[i].name;
var finalDotPosition = fullName.lastIndexOf(".");
if(finalDotPosition > -1)
{
var repname = fullName.substr(0 , finalDotPosition);
}                
var exportFilePath = thumbs[i].parent.spec + "/" + repname + "_new.jpg";
var size = "0";
size = tbPanel.txt2.text;
if (size > "0")
{
var bm1 = bm.resize(size, "bicubicSharper");
bm1.exportTo(new File(exportFilePath), tbPanel.slider1.value);
}
else
{
bm.exportTo(new File(exportFilePath), tbPanel.slider1.value);
}
}
}
}
}
}
}
for(var i = 0;i < app.documents.length;i++)
{
addScriptPalette(app.documents[i]);
}
}
Photo of David Converse

David Converse

  • 448 Posts
  • 132 Reply Likes

Posted 11 months ago

  • 2
Photo of Paul Riggott

Paul Riggott

  • 359 Posts
  • 143 Reply Likes
This will not work with Windows as checkboxs and radiobuttons do not show with TabbedPalette in Bridge 2018.
Yes this has been reported on this forum, but Bridge SCRIPTUI bugs only accumulate and never get fixed!


Why haven't you added cr2,nef etc as these should work as well?
Photo of David Converse

David Converse

  • 448 Posts
  • 132 Reply Likes
Oy. I'm testing it now on Windows, and such bugs.

Statictext line wrapping is broken. I can't get it to recognize return or linefeed characters (edittext and Mac both work fine with the multiline property.)

CR2 and NEF weren't in the original Adobe snippet, didn't think to include them.

As for checkbox display, I stumbled upon some info that might help Adobe fix it. A checkbox will display on top of some other elements but the clickable area is next to the drawn box. Try this snippet:

tbPanel.txtField3Lbl = tbPanel.add('statictext', [15,180,151,210], 'Preserve Colorspace');
tbPanel.cb1=tbPanel.add('checkbox',[135,182,180,198]);


It does work, you have to click immediately to the right of the checkbox to toggle it. Windows 7 Pro, Bridge CC 2018. This didn't work with an edittext field.
Photo of Paul Riggott

Paul Riggott

  • 359 Posts
  • 143 Reply Likes
Mmmm didn't work for me in Windows 10 and Bridge 2018
Yes the checkbox is displayed but you can not toggle it off/on

I really wish Adobe would fix these bugs!

Oh another addition that would help is:-
bm = bm.rotate(thumb.rotation);

Then it would auto rotate if required.
Photo of David Converse

David Converse

  • 448 Posts
  • 132 Reply Likes
Yeah this is some sort of layout bug when drawing the Windows control in ScriptUI. I tried to figure out how to get it to work but couldn't, the clickable area and control are in different places so you have to click immediately to the right of the box. Ridiculous.

I may just add rotation and polish it a bit and release a script for the Mac only, since that at least works so far. I'm not really a coder, just hacked away on this to learn more about ScriptUI and ExtendScript.
Photo of Paul Riggott

Paul Riggott

  • 359 Posts
  • 143 Reply Likes
That would be great, there are a lot of Mac users that would love it.
I use my own version.

By the way this is using CS5, the last version that works okay :)
Photo of David Converse

David Converse

  • 448 Posts
  • 132 Reply Likes
I rarely batch anything at home (on the Mac) and typically do RAW processing in Lightroom anyway. At work, I use Image Processor Pro (Windows) because I need to retain metadata and save to multiple sizes.

BTW I've seen your script repository, great work! I don't have time to do much coding and its mostly for my personal use when I do. Adding a folder location and custom filename were on the list as well, just a matter of having free time.
Photo of Paul Riggott

Paul Riggott

  • 359 Posts
  • 143 Reply Likes
Yes Ross did a great job with I.P.P.
I do very little now, just for my own use, I have just added jpg,png,tif,wmf,bmp,gif,emf to/from any of these formats (Windows only)

Please do finish your script as most people are put off using Bridge scripting and they will find it very useful.
Photo of David Converse

David Converse

  • 448 Posts
  • 132 Reply Likes
I have come quite a ways with this palette. Current state, about 80% implemented...

Photo of James Lockman

James Lockman, Employee

  • 8 Posts
  • 4 Reply Likes
David, you need to package that and get it on the Exchange. 
Photo of David Converse

David Converse

  • 448 Posts
  • 132 Reply Likes
Photo of Dan Clements

Dan Clements

  • 7 Posts
  • 5 Reply Likes
David:

I started this thread over four years ago and had given up. Your script works great! I would be happy to pay for it.

Thanks,

Dan Clements
+1.425.418.8755
dan@e-clements.com
www.e-clements.com
Photo of David Converse

David Converse

  • 448 Posts
  • 132 Reply Likes
No need to pay, I decided to release this as open source freeware. I'm still in beta testing, will have a new build posted tonight.