Skip to main content
Participating Frequently
March 8, 2023
Answered

Looking for a Script for Bridge..

  • March 8, 2023
  • 1 reply
  • 1264 views

Can anyone direct me where to build a script for Bridge.

 

I would like to build a script to convert the Dimensions (in inches) metadata to the dimensions if the the size was reduced to 3" on the largest side and put it in the description metadate line.

 

 

This topic has been closed for replies.
Correct answer Lumigraphics

I would greatly appreciate that.  Thank you,


This should work. Save as PLAIN TEXT with .jsx extension and copy into the Bridge Startup Scripts folder. Restart Bridge, select your files, right-click "Ratio to Description".

 

 

/*
Utility Pack Scripts created by David M. Converse ©2018-23

This script writes dims to description

Last modified 3/9/2023

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#target bridge
if(BridgeTalk.appName == 'bridge'){
    var ratioCmd = MenuElement.create('command', 'Ratio to Description', 'after Thumbnail/Open', this.menuID); //add to Contextual menu
    }
ratioCmd.onSelect = function(){
    ratioMain();
    }
ratioMain = function(){
    var descThumbs = app.document.selections; //get selected thumbnails
    var dims = '';
    var h = 0;
    var w = 0;
    if(ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
    if(!descThumbs.length) return; //nothing selected
    for(var a in descThumbs){ //loop through thumbs
        if(!descThumbs[a].container){
            try{
                var descMeta = descThumbs[a].synchronousMetadata;
                var descXMP = new XMPMeta(descMeta.serialize());
                descXMP.deleteProperty(XMPConst.NS_DC, 'description');
                h = descThumbs[a].core.quickMetadata.height;
                w = descThumbs[a].core.quickMetadata.width;
                if(h > w){
                    dims = '3\"H x ' + (w/h*3).toString() + '\"W'; 
                    }
                else{
                    dims = (h/w*3).toString() +'\"H x ' +  '3\"W'; 
                    }
                descXMP.setLocalizedText(XMPConst.NS_DC, 'description', null, 'x-default', dims);
                var descUpdatedPacket = descXMP.serialize(XMPConst.SERIALIZE_OMIT_PACKET_WRAPPER | XMPConst.SERIALIZE_USE_COMPACT_FORMAT);
                descThumbs[a].metadata = new Metadata(descUpdatedPacket); //write to file
                }
            catch(e){
                alert(e + e.line);
                }
            }
        }
    }

 

1 reply

Brainiac
March 8, 2023

This can certainly be done, but be aware that images are measured in pixels and inches are a derived property. If PPI data is changed or deleted, the derived inch measurement will also change.

SDHRSAuthor
Participating Frequently
March 8, 2023

Thank you for the heads up.  Would it be possible to have the script over write itself up request?

LumigraphicsCorrect answer
Brainiac
March 9, 2023

I would greatly appreciate that.  Thank you,


This should work. Save as PLAIN TEXT with .jsx extension and copy into the Bridge Startup Scripts folder. Restart Bridge, select your files, right-click "Ratio to Description".

 

 

/*
Utility Pack Scripts created by David M. Converse ©2018-23

This script writes dims to description

Last modified 3/9/2023

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#target bridge
if(BridgeTalk.appName == 'bridge'){
    var ratioCmd = MenuElement.create('command', 'Ratio to Description', 'after Thumbnail/Open', this.menuID); //add to Contextual menu
    }
ratioCmd.onSelect = function(){
    ratioMain();
    }
ratioMain = function(){
    var descThumbs = app.document.selections; //get selected thumbnails
    var dims = '';
    var h = 0;
    var w = 0;
    if(ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
    if(!descThumbs.length) return; //nothing selected
    for(var a in descThumbs){ //loop through thumbs
        if(!descThumbs[a].container){
            try{
                var descMeta = descThumbs[a].synchronousMetadata;
                var descXMP = new XMPMeta(descMeta.serialize());
                descXMP.deleteProperty(XMPConst.NS_DC, 'description');
                h = descThumbs[a].core.quickMetadata.height;
                w = descThumbs[a].core.quickMetadata.width;
                if(h > w){
                    dims = '3\"H x ' + (w/h*3).toString() + '\"W'; 
                    }
                else{
                    dims = (h/w*3).toString() +'\"H x ' +  '3\"W'; 
                    }
                descXMP.setLocalizedText(XMPConst.NS_DC, 'description', null, 'x-default', dims);
                var descUpdatedPacket = descXMP.serialize(XMPConst.SERIALIZE_OMIT_PACKET_WRAPPER | XMPConst.SERIALIZE_USE_COMPACT_FORMAT);
                descThumbs[a].metadata = new Metadata(descUpdatedPacket); //write to file
                }
            catch(e){
                alert(e + e.line);
                }
            }
        }
    }