0

I am developing a script for Adobe Bridge CS6. For the moment, all I want to do is to access the size (width and height) of a thumbnail that the user has selected and show it, either on a popup or on the console. Here is my script:

    function TestBridge() {
       this.requiredContext = "\tAdobe Bridge must be running.\n\tExecute against Bridge as the Target.\n";
        }

    TestBridge.prototype.run = function() {

    if(!this.canRun())
    {
        return false;
    }

    var selectedThumbnails = app.document.getSelection();
    if (selectedThumbnails.length > 0) {
        $.writeln("MEEEEEPT");
        var thumb = selectedThumbnails[0];
        var x = thumb.core.preview.preview.width;
        var y = thumb.core.preview.preview.height;

      //alert('MEEEEEPT: x = ' + x + ', y = ' + y);
        $.writeln("MEEEEEPT: x = " + x + ", y = " + y);
        return true;
        }
    $.writeln("MOOO");
    return false;
    }


TestBridge.prototype.canRun = function()
 {
    // Must be running in Bridge & have a selection
    if( (BridgeTalk.appName == "bridge") && (app.document.selectionLength == 1)) {
        return true;
    }

    // Fail if these preconditions are not met.  
    // Bridge must be running,
    // There must be a selection.
    $.writeln("ERROR:: Cannot run.");
    $.writeln(this.requiredContext);
    return false;
}

The only problem is that... well, it doesnt work. I open it on ExtendScript Toolkit, set the target to Bridge CS6, hit "Run"... and all that happens is that the console says "Result: canRun()".

Looking at other code samples from Adobe, I see that the structure of their scripts is pretty much the same as mine, so I don't really know what I'm doing wrong.

Edit: what I needed was to add in the end a line to call the function, like so:

new.TestBridge.run();

Silly, silly mistake.

PaulJ
  • 1,646
  • 5
  • 33
  • 52
  • Try setting `alerts` just before your `return` statements and make sure they are all returning correctly. Are you sure one of your functions isn't returning `false`? – bgmCoder Apr 18 '14 at 01:10
  • 1
    Where are you calling the actual function? – bgmCoder Apr 18 '14 at 01:24
  • Erm... nowhere :-). I realized hours later that the sample scripts from Adobe had at the end a single line like `new FunctionName().run();` . Since it was a single line at the very end of the script, I hadn't seen it. – PaulJ Apr 18 '14 at 10:07
  • Can you please update your script to show your function call? – bgmCoder Apr 18 '14 at 19:42

0 Answers0