This is a collage of recent thoughts from Xbytor and myself.
Xbytor deserves the real credit for his BridgeTalk.prototype.sendSynch function.
The script runs from Photoshop and obtains the list of files and folders selected in Bridge as a single comma separated list. It is a significant improvement on my own previous methods in that it does not use an intermediate text file:
Code: Select allBridgeTalk.prototype.ah_getBTSpecifier = function (tApp) {
if (BridgeTalk.appName == tApp) return tApp + '-' + app.version.replace(/\..*$/,"")
else if (BridgeTalk.appName == 'bridge' && tApp == 'photoshop') {
return tApp + '-' + Number(Number(app.version.replace(/\..*$/,"")) + 8);}
else if (BridgeTalk.appName == 'photoshop' && tApp == 'bridge') {
return tApp + '-' + Number(Number(app.version.replace(/\..*$/,"")) - 8);
}
}
BridgeTalk.prototype.sendSynch = function(timeout) {
var self = this;
self.onResult = function(res) {
this.result = res.body;
this.complete = true;
}
self.complete = false;
self.send();
if (timeout) {
var i = 0;
while(!self.complete) {
BridgeTalk.pump(); // process any outstanding messages
$.sleep(1000);
if (i == timeout) {
if (!confirm("Still Collection Bridge Data, Continue?")) return;
else i = 0;
}
else i++;
}
}
var res = self.result;
self.result = self.complete = self.onResult = undefined;
return res;
};
function getBridgeSelectionsAsString() {
function getBridgeFiles() {
var v = app.document.selections;
var files = new Array();
for (var i = 0; i < v.length; i++) {
files = v.spec;
}
return files;
}
if (BridgeTalk.appName != "photoshop" || BridgeTalk.appVersion.replace(/\..*$/,"") < 9) {
alert("This only works from Photoshop CS2/CS3");
return;
}
var bt = new BridgeTalk();
var bridgeApp = bt.ah_getBTSpecifier("bridge");
if (!BridgeTalk.isRunning(bridgeApp)) {
alert("Please launch " + bridgeApp + " then click OK");
if (!BridgeTalk.isRunning(bridgeApp)) return;
}
bt.target = bridgeApp;
bt.body = getBridgeFiles.name + "();" + getBridgeFiles.toString();
return bt.sendSynch(2);
}
alert(getBridgeSelectionsAsString());
You could also get it to return a toSource() specification of the file list but I find that generally less useful as I prefer to recreate my file list one file at a time.
You could also get it to search to various depths within any folders selected from Bridge. If the folders have been cached this can be significantly faster than doing so from Photoshop.
To do that all you need to do is write a folder-scanning function and embed it within the getBridgeFiles() function. The same would apply to searching for meta-data from Bridge, it can be a lot faster than doing the same from Photoshop.
Andrew
Getting Bridge Selections from Photoshop
Getting Bridge Selections from Photoshop
When using this how do you determine if the returned selections are files or folders? Do you assume if it doesn't have an extension it's a folder?
Mike
Mike
Getting Bridge Selections from Photoshop
If (files instanceof File) {}
else if (files instanceof Folder) {}
Andrew
else if (files instanceof Folder) {}
Andrew
Getting Bridge Selections from Photoshop
I must be missing a step somewhere. Lets say I have only 1 thumbnail selected in Bridge and it's the folder c/temp/test
var selections = getBridgeSelectionsAsString();// "/c/temp/test"
var t = new File(selections);// File /c/temp/test
alert(t instanceof File);// true
alert(t.exists);// true
var selections = getBridgeSelectionsAsString();// "/c/temp/test"
var t = new File(selections);// File /c/temp/test
alert(t instanceof File);// true
alert(t.exists);// true
Getting Bridge Selections from Photoshop
Try this:
Code: Select allar selections = getBridgeSelectionsAsString();// "/c/temp/test"
var t = File(selections);
alert(t instanceof File);
alert(t instanceof Folder);
alert(t.exists);// true
There are apparently situations where you can 'new File()' on a folder and get a valid File object. I wouldn't write to it, though. It would probably hose the directory.
-X
Code: Select allar selections = getBridgeSelectionsAsString();// "/c/temp/test"
var t = File(selections);
alert(t instanceof File);
alert(t instanceof Folder);
alert(t.exists);// true
There are apparently situations where you can 'new File()' on a folder and get a valid File object. I wouldn't write to it, though. It would probably hose the directory.
-X
Getting Bridge Selections from Photoshop
I knew from past typos that 'new File()' will return a file object from almost anything. So I add a exists check to make sure it was a valid file. It threw me when it seems that a folder can also be a file.
I think that I have never run into this before because the older version of this that I have uses toSource/eval to pass the array.
Thanks for the just 'file()' info.
Mike
I think that I have never run into this before because the older version of this that I have uses toSource/eval to pass the array.
Thanks for the just 'file()' info.
Mike
Getting Bridge Selections from Photoshop
i selected five or more images in bridge, i want to open this files from bridge to photoshop and copy all of them in single active document and when they copy in active document they all resize to forth size of document
http://ps-scripts.com/bb/viewtopic.php?t=1309
i find topic from this site..
thanks
http://ps-scripts.com/bb/viewtopic.php?t=1309
i find topic from this site..
thanks