0

I am trying to get the parent file path of a selected image thumbnail in Adobe Bridge CS5.1 to pass it on to a shell script. An Applescript wraps a tiny javascript command in command like this:

set js to "app.document.selections[0].spec.parent.name;" # parent of 1st selected image
tell application "Adobe Bridge CS5.1" # target adobe product
    set theResult to do javascript js # fire away, waiting for return value
end tell 

The javascript reports the correct value — I tested the output within Bridge via alert. Alas, the do javascript command does not return any value, so I added an explicit return statement:

set js to "return app.document.selections[0].spec.parent.name;"

throws an error in AppleScript Editor.app:

error "Adobe Bridge CS5.1 got an error: AppleEvent handler failed." number -10000

What am I doing wrong? NB: I just need the path, I don’t care about how it is done.

2

I think you would have to go via Photoshop using BridgeTalk to get the path.

function getPathFromBridge(){
    function script(){
        var Path = new File(encodeURI(app.document.selections[0].spec.parent)); 
        return Path.toSource();
    }
    var filePath='';
    var bt = new BridgeTalk();
    bt.target = "bridge";
    bt.body ="var ftn = " + script.toSource() + "; ftn();";
    bt.onResult = function( inBT ) { filePath = decodeURI(eval( inBT.body));}
    bt.onError = function( inBT ) { filePath = '';}
    bt.send(4);
    if ( undefined == filePath ) filePath = '';
    return decodeURI(filePath); 
}
  • In the end, I feel that Adobe scripting can turn one insane. – myhd Jan 15 '13 at 11:17
1

You can't use a return in javascript, except in a function.

Updated : Ok, I did a test, if I put the result of the javascript command into a javascript variable, the result in AppleScript will be this string : undefined

So, use this set js to "app.document.selections[0].parent.spec;"

  • Thank you for your answer! Unfortunately, I still get the AppleEvent handler failed." number -10000 error. It’s driving me insane. – myhd Aug 7 '12 at 15:56
  • 1
    It seems that the syntax is not correct. try this set js to "tPath = app.document.selections[0].parent.spec;" -- Important, the parent property : The value is undefined for thumbnails added to the root level of app.favorites. – jackjr300 Aug 7 '12 at 17:13
  • 1
    You are right, syntax was incorrect. Thank you for the fix! Still no return from Bridge. Maybe the mechanism is broken? – myhd Aug 7 '12 at 19:35
  • I updated my answer. – jackjr300 Aug 7 '12 at 21:06
  • 1
    @myhd: See my answer to your question on SO, but I agree that the functionality is broken (intentionally or otherwise) for Bridge. – Philip Regan Sep 5 '12 at 13:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .