Skip to main content
andrewn63997035
Participating Frequently
Jul 22, 2019 7:46 PM UTC
Answered

Bridge Script to copy and move first image of filename set?

I have a folder with 1000s of images I'd like to grab the first image to make a thumbnail of.

For example, the images are named like this:

228837.jpg

228837a.jpg

228837b.jpg

228837c.jpg

228837d.jpg

I need to figure out a script that would pull the first image (non-alphabetical sequential). In this example, it would be 228837.jpg and would like to select all instances of non-alphabetical sequential and copy it to a folder called "thumbnails".

I've been searching and can't seem to figure it out. I would need it to check the active folder I'm in while in Bridge, and then throw into a sub-folder I'd call thumbnails. Any advice?

This topic is closed to new replies. Start a new post to keep the conversation going.
SuperMerlin
SuperMerlinCorrect answer
Inspiring
Jul 23, 2019 7:44 AM UTC

This will create a folder off the selected folder...

#target bridge  

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

copyThumbs = new MenuElement("command", "Copy Thumbnails", "at the end of Tools");

}

copyThumbs .onSelect = function () {

var folder = Folder(app.document.thumbnail.path);

if(!folder.exists){

   alert("You are not in a valid folder. Is this a collection?");

    return;

}

var copyFolder = Folder(folder + "/Thumbnails");

if (!copyFolder.exists) copyFolder.create();

var copied =0;

var sels = app.document.visibleThumbnails;

var count = sels.length;

for(var z =0;z<count;z++){

var Name = decodeURI(sels.spec.name.replace(/\.[^\.]+$/, ''));

if(Name.match(/^[-+]?\d*$/)){

    new Thumbnail(sels).copyTo(copyFolder);

    copied++;

    }

}

alert(copied + " Thumbnail copied");

};

4 replies

SuperMerlin
Inspiring
Jul 22, 2019 8:41 PM UTC

Here is a start for you:-

#target bridge  

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

copyThumbs = new MenuElement("command", "Copy Thumbnails", "at the end of Tools");

}

copyThumbs .onSelect = function () {

    //CHANGE FOLDER TO SUIT!!!!!!!!!!!!!!!!!!!!!!

var copyFolder = Folder("/d/thumbnails");

var copied =0;

if(!copyFolder.exists) copyFolder.create();

var sels = app.document.visibleThumbnails;

var count = sels.length;

for(var z =0;z<count;z++){

var Name = decodeURI(sels.spec.name.replace(/\.[^\.]+$/, ''));

if(Name.match(/^[-+]?\d*$/)){

    new Thumbnail(sels).copyTo(copyFolder);

    copied++;

    }

}

alert(copied + " Thumbnail copied");

};

Translate
andrewn63997035
Participating Frequently
Jul 22, 2019 9:28 PM UTC

Wow! Got it to work, kind of.

The only thing I can't figure out is how to name the folder structure to create the folder in the current directory I'm working in.

For example, I have 100s of folders and would need to have the thumbnail folder become the subdirectory within the folder I'm working in.

Translate
SuperMerlin
SuperMerlinCorrect answer
Inspiring
Jul 23, 2019 7:44 AM UTC

This will create a folder off the selected folder...

#target bridge  

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

copyThumbs = new MenuElement("command", "Copy Thumbnails", "at the end of Tools");

}

copyThumbs .onSelect = function () {

var folder = Folder(app.document.thumbnail.path);

if(!folder.exists){

   alert("You are not in a valid folder. Is this a collection?");

    return;

}

var copyFolder = Folder(folder + "/Thumbnails");

if (!copyFolder.exists) copyFolder.create();

var copied =0;

var sels = app.document.visibleThumbnails;

var count = sels.length;

for(var z =0;z<count;z++){

var Name = decodeURI(sels.spec.name.replace(/\.[^\.]+$/, ''));

if(Name.match(/^[-+]?\d*$/)){

    new Thumbnail(sels).copyTo(copyFolder);

    copied++;

    }

}

alert(copied + " Thumbnail copied");

};

Translate