Skip to main content
Participating Frequently
July 22, 2012
Answered

Can I do this?

  • July 22, 2012
  • 1 reply
  • 3258 views

Hi all,

Im new to bridge scripting

I can code in actionscript, javascript so I should not have problems, but before getting in on it I'd like to know if the following is possible:

I'd like to do a script that:

- ask the user for a date (ddmm, for example=1907)

- ask the user for a folder on my pc

- for each Photocamera connected:

     - read a file inside the photocamera (in DCIM) named id.txt (a file that I placed manually)

     - read the content of the file and extract a string from it (the ID, let's say = "34")

     - read all subdirs contained in DCIM

     - find the subdir that ends with the provided date (for example: 107_1907)

     - copy all files from that subdir to the folder in my PC (set at the beginning) renaming files as hhmmss_ID.jpeg (hhmmss=picture creatione time) for example=124028_34.jpeg

is this possible?

thanks

This topic has been closed for replies.
Correct answer Paul Riggott

some news:

From what I've understood camera that do not presente themselves as hd, are trated via the WIA protocol.

Actually the images are just referable/enumerable but not accessible.

So what I'd need is some way to perform an automatic import of the pictures,

I searched 3 days on google but couldn't fine any software that permites a batch/scripting capture neither a capture command via command line...

The Adobe photodownloader is a separate exe (in the bridge dir) but not usable via command line...

tricky...


If you wanted to try card readers, this should be a start for you...

#target bridge

if( BridgeTalk.appName == "bridge" ) { 

cardReader = MenuElement.create("command", "Process Card Reader", "at the end of Tools","cardReader");

}

cardReader.onSelect = function () {

var driveList = getCameraInfo();

var win = new Window( 'dialog', '' );

g = win.graphics;

var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]);

g.backgroundColor = myBrush;

win.orientation='stack';

win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});

win.g1 = win.p1.add('group');

win.g1.orientation = "row";

win.title = win.g1.add('statictext',undefined,'Get Files from Card Reader');

win.title.alignment="fill";

var g = win.title.graphics;

g.font = ScriptUI.newFont("Georgia","BOLDITALIC",22);

win.g5 =win.p1.add('group');

win.g5.orientation = "row";

win.g5.alignment='fill';

win.g5.spacing=10;

win.g5.st1 = win.g5.add('statictext',undefined,'Camera');

win.g5.dd1 = win.g5.add('dropdownlist');

win.g5.st2 = win.g5.add('statictext',undefined,'Serial No:');

win.g5.dd2 = win.g5.add('dropdownlist');

win.g5.st2 = win.g5.add('statictext',undefined,'ID:');

win.g5.dd3 = win.g5.add('dropdownlist');

win.g10 =win.p1.add('group');

win.g10.orientation = "row";

win.g10.alignment='fill';

win.g10.st1 = win.g10.add('statictext',undefined,'Please enter date ddmm');

win.g10.et1 = win.g10.add('edittext',undefined,'');

win.g10.et1.preferredSize=[60,20];

win.g10.et1.onChanging = function() {

  if (this.text.match(/[^\-\.\d]/)) {

    this.text = this.text.replace(/[^\-\.\d]/g, '');

  }

};

win.g5.dd1.onChange=function(){

    win.g5.dd2.selection = this.selection.index;

    win.g5.dd3.selection = this.selection.index;

    }

win.g5.dd2.onChange=function(){

    win.g5.dd1.selection = this.selection.index;

    win.g5.dd3.selection = this.selection.index;

    }

win.g5.dd3.onChange=function(){

    win.g5.dd1.selection = this.selection.index;

    win.g5.dd2.selection = this.selection.index;

    }

win.g15 =win.p1.add('group');

win.g15.orientation = "row";

win.g15.alignment='fill';

win.g15.st1 = win.g15.add('statictext',undefined,'Please select output folder...');

win.g20 =win.p1.add('group');

win.g20.orientation = "row";

win.g20.alignment='fill';

win.g20.et1 = win.g20.add('edittext',undefined,'');

win.g20.et1.preferredSize=[320,20];

win.g20.et1.enabled=false;

win.g20.bu1 = win.g20.add('button',undefined,'Browse');

win.g20.bu1.onClick = function() {

  outputFolder = Folder.selectDialog("Please select the source folder",Folder(app.document.presentationPath));

if(outputFolder !=null){

  win.g20.et1.text =  decodeURI(outputFolder.fsName);

  }

}

win.g200 =win.p1.add('group');

win.g200.orientation = "row";

win.g200.alignment='center';

win.g200.bu1 = win.g200.add('button',undefined,'Process');

win.g200.bu1.preferredSize=[190,35];

win.g200.bu2 = win.g200.add('button',undefined,'Cancel');

win.g200.bu2.preferredSize=[190,35];

for(var x in driveList){

    win.g5.dd1.add('item',driveList[1]);//Camera Name

    win.g5.dd2.add('item',driveList[2]);//Serial Number

    win.g5.dd3.add('item',driveList[3]);//ID

    }

win.g5.dd1.selection=0;

win.g5.dd2.selection=0;

win.g200.bu1.onClick=function(){

if(driveList.length<1){

    alert("There are no drives to process!");

    return;

    }

if(win.g10.et1.text == ''){

    alert("No date has been entered!");

    return;

    }

var dayMonth = win.g10.et1.text.toString().replace(/^\s+|\s+$/g,'');

if(dayMonth.toString().length != 4){

    alert("The day month should be ddmm ");

    return;

    }

if(dayMonth.toString().match(/^\d{2}/) >31 || dayMonth.toString().match(/^\d{2}/) < 1){

    alert("Incorrect day entered");

    return;

    }

if(dayMonth.toString().match(/\d{2}$/) >12 || dayMonth.toString().match(/\d{2}$/) < 1){

    alert("Incorrect month entered");

    return;

    }

if(win.g20.et1.text == ''){

    alert("No output folder has been selected");

    return;

    }

if(!outputFolder.exists){

    alert("The output folder does not exist!");

    return;

    }

win.close();

var rex = new RegExp(dayMonth,'i');

var folderList= new Array();

for(var f in driveList){

var folderList= new Array();

folderList = FindAllFolders(Folder("/"+driveList[0]+"/DCIM/"), folderList); 

var ID = driveList[3];

var fileList = new Array();

for(var k in folderList){

    if(decodeURI(folderList.name).match(rex)){

        fileList = folderList.getFiles("*.*");

        for(var t in fileList){

            if(fileList instanceof Folder ) continue;

            var thumb = new Thumbnail(File(fileList));

            var md = thumb.synchronousMetadata;

            var EXT = decodeURI(thumb.spec.name).toLowerCase().match(/[^\.]+$/);

            try{

            var DateTimeOriginal = md.read("http://ns.adobe.com/exif/1.0/","exif:DateTimeOriginal").toString().match(/.{8}$/).toString().replace(/:/g,'');

            }catch(e){alert(e + " " +e.line); return;}

            var saveFile = File(outputFolder + "/" + DateTimeOriginal + "_" + ID + "." + EXT);

            fileList.copy(saveFile);

            }

        break;

        }

    }

    }

alert("Process complete");

}

win.show();

}

function getCameraInfo(){

var myDrives=new Array();

myDrives = getWinDriveList();

var cInfo = new Array();

for(var z in myDrives){

var folderList=[];

var ID='';

var IDFile = File("/"+myDrives+"/DCIM/ID.txt")

if(!IDFile.exists){

    ID=99;

    }else{

IDFile.open('r');

var dat = IDFile.read();

IDFile.close();

ID = dat.match(/\d{2}/);

        }

folderList = FindAllFolders(Folder("/"+myDrives+"/DCIM/"), folderList);

var thumb = new Thumbnail(File(Folder(folderList[0].getFiles("*.*")[0])));

var md = thumb.synchronousMetadata;

var model = md.read("http://ns.adobe.com/tiff/1.0/","tiff:Model");

var serial = md.read("http://ns.adobe.com/exif/1.0/aux/","aux:SerialNumber");

cInfo.push([[myDrives],[model],[serial],[ID]]);

    }

return cInfo;

}

function getWinDriveList(){

var allHDD = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");

var hddExist = new Array();

for(var d in allHDD){

if(Folder("/"+allHDD+"/DCIM/").getFiles("*.*").length > 0) hddExist.push(allHDD);  

    }

return hddExist;

};

function FindAllFolders( srcFolderStr, destArray) {

var fileFolderArray = Folder( srcFolderStr ).getFiles();

for ( var i = 0; i < fileFolderArray.length; i++ ) {

  var fileFoldObj = fileFolderArray;

  if ( fileFoldObj instanceof File ) {  

  } else {

         destArray.push( Folder(fileFoldObj) );

  FindAllFolders( fileFoldObj.toString(), destArray );

  }

}

return destArray;

};


1 reply

Paul Riggott
Inspiring
July 22, 2012

It sounds feasible as there is no specific Bridge scripting required, maybe a nice UI would help. You haven't said what version of Bridge as there as some problems with Bridge CS6 if you wanted to use colours/text size or use thumbnails in an UI.

ZRock2Author
Participating Frequently
July 22, 2012

thanks

I thought that Bridge's javascript was somehow proprietary and limited to

bridge's classes and methods... So, if I've well understood, Bridge will

interpret a normal javascript code that already supports html5 standards

like File and FileReader (otherwise there is no way to open/read local files), right?

Paul Riggott
Inspiring
July 22, 2012

Bridge and Photoshop use ExtendScript, It also has it's own IDE that gets installed with Photoshop.

ExtendScript Toolkit. You will find that there is help in the IDE also there are the PDFs in the Photoshop application scripting folder on Windows:

C:\Program Files\Adobe\Adobe Photoshop CS5 (64 Bit)\Scripting\Documents

As an example of creating a text file:-

var file = new File(Folder.desktop + "/Test Textfile.txt");

file.open("w", "TEXT", "????");

$.os.search(/windows/i)  != -1 ? file.lineFeed = 'windows'  : file.lineFeed = 'macintosh';

file.writeln("This is a line of text");

file.close();

Besides this forum you will find hundreds of examples @ http://www.ps-scripts.com/bb/

If you get stuck on anything please ask.