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

Demo metadata template popup

LEGEND ,
Dec 11, 2023 Dec 11, 2023

Copy link to clipboard

Copied

Bridge allows saving and applying metadata templates but it can be a bit fiddly as you must be showing the Metadata panel and have to hit small submenus.

 

This script puts a popup menu in the bottom navbar which lets you apply templates much more easily.

 

I wrote this for my own use and am releasing it as a demo here.

 

Save this script as PLAIN TEXT with ".jsx" file extension and place in the Bridge Scripts folder. Relaunch Bridge to make it show up in the Tools menu.

 

 

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

This script is a working demo of a metadata template popup in the navbar

Last modified 12/7/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 metapopCmd =  MenuElement.create('command', 'Meta Popup...', 'at the end of Tools');
    }
metapopCmd.onSelect = function(){
    mpbuild();
    metapopCmd.enabled = false;
    }

mpbuild = function(){
    try{
        var mpbar = app.document.navbars.filesystem.bottom;
        var templateFiles = null;
        if(Folder.fs == 'Windows'){
            var temPath = Folder(Folder.userData.path +'/Roaming/Adobe/XMP/Metadata Templates/');
            }
        else{
            var temPath = Folder(Folder.userData.path + '/Application Support/Adobe/XMP/Metadata Templates/');
            }
        mpbar.orientation = 'row';
        mpbar.alignChildren = ['right', 'fill'];
        mpbar.margins = [0, 4, 0, 0];
        mppanel_1 = mpbar.add('panel', undefined, '', {borderStyle:'sunken'});
        mppanel_1.orientation = 'row';
        mppanel_1.alignChildren = ['fill', 'fill'];
        mppanel_1.margins = [15, 2, 10, 2];
        mppanel_1.ddl = mppanel_1.add('dropdownlist', undefined, undefined);
        getTemplates();
        mppanel_1.ddl.selection = 0;
        mppanel_1.rb1 = mppanel_1.add('radiobutton', undefined, 'Append');
        mppanel_1.rb2 = mppanel_1.add('radiobutton', undefined, 'Replace');
        mppanel_1.rb2.value = true;
        var mptype = 'replace';
        var mpset = mppanel_1.ddl.selection.text;
        mpbar.layout.layout(true); //do layout
        mpbar.visible = true; //make visible

        function getTemplates(){
            mppanel_1.ddl.add('item', 'Metadata');
            templateFiles = temPath.getFiles('*.xmp'); //get list of metadata templates
            if(templateFiles.length == 0){ //no metadata templates
                return;
                }
            else{
                for(var k = 0;k < templateFiles.length;k++){ //build dropdownlist
                    var templateListItem = templateFiles[k].displayName.split('.'); //split into array
                    mppanel_1.ddl.add('item', templateListItem[0]); //add first item array (text before first dot)
                    }
                }
            }

        mppanel_1.ddl.onActivate = function(){
            try{
                if(templateFiles.length != temPath.getFiles('*.xmp').length){
                    mppanel_1.ddl.removeAll();
                    getTemplates();
                    }
                }
            catch(e){
                Window.alert(e + e.line);
                }
            }

        mppanel_1.ddl.onChange = function(){
            try{
                mpset = mppanel_1.ddl.selection.text;
                if(mppanel_1.rb1.value == true){
                    mptype = 'append';
                    }
                else{
                    mptype = 'replace';
                    }
                if(mppanel_1.ddl.selection == 0) return;
                var mpThumbs = app.document.selections; //get selected thumbnails
                if(!mpThumbs.length) return; //nothing selected
                if(!File(temPath.path + '/' + mpset + '.xmp').exists){
                    for(var a = 0; a < mpThumbs.length; a++){
                        if(mpThumbs[a].hasMetadata){
                            var mpMeta = mpThumbs[a].synchronousMetadata;
                            mpMeta.applyMetadataTemplate(mpset, mptype);
                            }
                        }
                    }
                else{
                    mppanel_1.ddl.removeAll();
                    getTemplates();
                    Window.alert('Metadata template ' + mpset + ' is missing, cannot apply. Please select a different metadata template.');
                    return;
                    }
                mppanel_1.ddl.selection = 0;
                }
            catch(e){
                Window.alert(e + e.line);
                }
            }
        }
    catch(e){
        Window.alert(e + e.line);
        }
    }

 

TOPICS
How to , Metadata , Scripting

Views

67

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
no replies

Have something to add?

Join the conversation