Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

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();
    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); 
}
share|improve this answer
    
In the end, I feel that Adobe scripting can turn one insane. –  myhd Jan 15 '13 at 11:17
add comment

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
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
show 1 more comment

Your Answer

 
discard

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.