Skip to main content
Participant
December 18, 2013
Question

Script : How to add a progress bar to XMP Writing script ?

  • December 18, 2013
  • 2 replies
  • 1332 views

Hi !

I have this script that works flawlessly but when i execute it on big video files ( > 1GB) bridge doesn't repaint and it looks like it's stuck. I would like to have a progress bar showing % remaining on the task and the name of the file being treated. Can someone point me into the right direction as my adobe scripting knowledge is not that great.

#target bridge  

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

descToTitle = MenuElement.create("command", "Log Comment to Description", "at the end of Tools");

}

descToTitle.onSelect = function () {

           if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

          

           var thumb = app.document.selections;

           for(var s in thumb){

                     if(thumb.hasMetadata){

                                        var selectedFile = thumb.spec;

                                        var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);

                                        var myXmp = myXmpFile.getXMP();

                                        var LogComment = myXmp.getProperty(XMPConst.NS_DM, "logComment");

                                        myXmp.deleteProperty(XMPConst.NS_DC, "description");

                                        myXmp.appendArrayItem(XMPConst.NS_DC, "description", LogComment, 0, XMPConst.ALIAS_TO_ALT_TEXT);

                                        myXmp.setQualifier(XMPConst.NS_DC, "description[1]", "http://www.w3.org/XML/1998/namespace", "lang", "x-default");

                              }

                                        if (myXmpFile.canPutXMP(myXmp)) {

                                        myXmpFile.putXMP(myXmp);

                                        myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);

                                         } else {

                      xmpFile.closeFile();

                                        }

                    }

}

Thx in advance for helping me !

This topic has been closed for replies.

2 replies

Participating Frequently
February 25, 2014

The free ScriptUI for dummies pdf by Peter Kahrel has a section on creating progress bars, and in general is extremely useful for understanding how to make UIs for adobe program scripts.

You can download it from here: http://www.kahrel.plus.com/indesign/scriptui.html

Pedro Cortez Marques
Legend
February 25, 2014

Sadly Bridge has several bugs regarding scriptUI and particulary arround progress bar that make us to work it arround.

On Bridge CS6 the framework of scriptUI is 'Combo'

On Photoshop CS6 the framework of scriptUI is 'Flex'

On CC I have not tested but I know Adobe is no longer planning on developing that.

It will be the html5 era for UI

The less experienced scripters will have to run to get the train and it is already far away.

Participating Frequently
February 27, 2014

Thanks for the info, I didn't realise this. The only scipring for Bridge I've done has been for CS5, and so far all the basic scriptui guide stuff has worked.

I hope adobe hurry up and add html5 to bridge, certainly would make like easier for script compatability across the adobe programs.

Pedro Cortez Marques
Legend
January 2, 2014

I am using this progress bar on bridge. I don't remember who gave it to me time ago.

Anyway I have adapt it to your script:

#target bridge  

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

descToTitle = MenuElement.create("command", "Log Comment to Description", "at the end of Tools");

}

descToTitle.onSelect = function () {

    if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

    var thumb = app.document.selections;

    //

    var progBar = new createProgressWindow("Work in Progress", "Please wait", false);

    for (var s in thumb) {

        if(thumb.hasMetadata) {

            var selectedFile = thumb.spec;

            var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);

            var myXmp = myXmpFile.getXMP();

            var LogComment = myXmp.getProperty(XMPConst.NS_DM, "logComment");

            myXmp.deleteProperty(XMPConst.NS_DC, "description");

            myXmp.appendArrayItem(XMPConst.NS_DC, "description", LogComment, 0, XMPConst.ALIAS_TO_ALT_TEXT);

            myXmp.setQualifier(XMPConst.NS_DC, "description[1]", "http://www.w3.org/XML/1998/namespace", "lang", "x-default");

        }

        //

        progBar.updateProgress (Math.floor((Number(s)+1)*(100/thumb.length)), "Waiting, " + Math.floor((Number(s)+1)*(100/thumb.length)) + "% completed.");

        //

        if (myXmpFile.canPutXMP(myXmp)) {

            myXmpFile.putXMP(myXmp);

            myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);

        } else {

            xmpFile.closeFile();

        }

    }

}

//////////////

function createProgressWindow(title, message, hasCancelButton) {

    var win;

    if (title == null) title = "Work in progress";

    if (message == null) message = "Please wait...";

    if (hasCancelButton == null) hasCancelButton = false;

    win = new Window("palette", "" + title, undefined);

    win.bar = win.add("progressbar", {x: 20,y: 12,width: 300,height: 20}, 0, 100);

    win.stMessage = win.add("statictext", {x: 10,y: 36,width: 320,height: 20}, "" + message);

    win.stMessage.justify = 'center';

    if (hasCancelButton) {

        win.cancelButton = win.add('button', undefined, 'Cancel');

        win.cancelButton.onClick = function() {

            win.close();

            throw new Error('User canceled the pre-processing!');

        }

    }

    this.reset = function(message) {

        win.bar.value = 0;

        win.stMessage.text = message;

        return win.update();

    }

    this.updateProgress = function(perc, message) {

        if (perc != null) {

            win.bar.value = perc;

        }

        if (message != null) {

            win.stMessage.text = message;

        }

    return win.update();

    }

    this.close = function() {

        return win.close();

    }

    win.center(win.parent);

    return win.show();

}