I'm experimenting with creating an external data file to track Bridge selections. I've come across two problems, one of which I have found a fix for, the other not.
If I obtain 'app.document.selections' following a 'select' event type, the list I get is actually the list prior to the latest selection. So if I had test1.jpg selected and switch to test2.jpg, app.document.selections[0] will be test1.jpg. The same applies to using 'deselect' that actual deselection does not show in the app.document.selections list when the event is triggered.
The fix for this is to use event type 'preview' which returns the latest selections at the moment you change the selection.
Unfortunately, preview does not update when you click when you deselect - and since deselect and select events both seem to come ahead of the updating of the selections list, using them does not work.
Any suggestions / ideas on this.
Andrew
Here is the code I am currently using:
onThumbnailEvent = function( event ){
if( event.object.constructor.name == "Thumbnail" ){
if( event.type == "preview" ) {
ah_CollectBridgeData();
return {handled:true};//stop processing event handlers
}
}
}
ah_writeData = function (tFile,tString) {
if (tFile.open('w')) {
if (tFile.write(tString)) tFile.close();
else throw ("Error saving file list\n" + tFile);
}
else throw ('Error, Data File Not Opened\n' + tFile);
}
ah_CollectBridgeData = function () {
var tFile = new File ('/c/Program Files/Adobe/Adobe Photoshop CS2/Presets/Scripts/nn-test3.dat');
var filestr = ah_fileThumbnailsToFilestr(app.document.selections);
ah_writeData(tFile,filestr);
}
ah_fileThumbnailsToFilestr = function( thumbnails ) {
var fileAr = new Array();
for ( var i = 0; i < thumbnails.length; i++ ) {
if(thumbnails.spec instanceof File) fileAr.push(thumbnails[ i ].spec);
}
return fileAr.toString();
}
// register the handler
allDocEventHandlers = { handler: onThumbnailEvent };
app.eventHandlers.push( allDocEventHandlers );