Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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];" # 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];"

throws an error in AppleScript

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.

share|improve this question
up vote 2 down vote accepted

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(); = "bridge";
    bt.body ="var ftn = " + script.toSource() + "; ftn();";
    bt.onResult = function( inBT ) { filePath = decodeURI(eval( inBT.body));}
    bt.onError = function( inBT ) { filePath = '';}
    if ( undefined == filePath ) filePath = '';
    return decodeURI(filePath); 
share|improve this answer
In the end, I feel that Adobe scripting can turn one insane. – myhd Jan 15 '13 at 11:17

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;"

share|improve this answer
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
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
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
@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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.