How to get the path of the selected Image in Adobe Bridge via Applescript?
-
21-12-2020 - |
Question
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.
Solution
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);
}
OTHER TIPS
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;"