Skip to main content
Known Participant
November 25, 2021
Answered

Bridge 2022 - Rename Scripts

  • November 25, 2021
  • 2 replies
  • 2395 views

Hello, 

I would like to be able to learn how to write a rename script on Bridge to do the following; first I want to know if this is something that's possible to do with bridge capabilities or what I could use to learn coding wise to write a script for it. 

Any info appreciated! 

 

Currently I have been doing it manually by duplicating the first image twice, running a batch rename with lower case and that gives me a b c d e - then use a automator function to delete the a + c but I am trying to simplify this process. 

 

Filename examples; files always follow this format but the digital counter is always random

1234567890123_000 ExampleNameRandom1.jpg

1234567890123_000 ExampleNameRandom2.jpg

1234567890123_000 ExampleNameRandom3.jpg

 

Output; desired out put to be in this sequence - not a + b + c + d + e instead b + d + e...etc

1234567890123_000_b

1234567890123_000_d

1234567890123_000_e

1234567890123_000_f

 

Regards,

 

This topic has been closed for replies.
Correct answer Kukurykus

Yes, in that sense it works. But it is making copies of the same file (first file) and then genrating copies renamed into that sequence. 

 

The idea is to take this for example. 

 

0111647050986_001 BLOUSE_0490.jpg
0111647050986_001 BLOUSE_0491.jpg
0111647050986_001 BLOUSE_0492.jpg
0112439780127_080 SHRUG_0869.jpg
0112439780127_080 SHRUG_0870.jpg
0112439780127_080 SHRUG_0871.jpg

 

And turn it into this. The regex extracts the first 17 digits of the original filename, and then renames them b,d,e,f,g,h if there is 3 images in this case, it renames it b,d,e only.

 

0111647050986_001_b.jpg
0111647050986_001_d.jpg
0111647050986_001_e.jpg
0112439780127_080_b.jpg
0112439780127_080_d.jpg
0112439780127_080_e.jpg

 

Would it be simpler to do a script that runs batch rename saved functions?

 

Run AUTO_RENAME_01.setting

Run AUTO_RENAME_02.setting

 

Instead of trying to do it in one step? I am not entirely sure what the limitations are, I apologize. 


 

function re() {
	rplcd = fle.path + '/' + decodeURI(fle.name)
	.replace(/ .+(?=\.jpg)/, '_' + bdefgh.shift())
	return File(rplcd).name != nme && rplcd
}

rnmng = new MenuElement('command', 'Batch Renaming',
'at the end of Thumbnail'), rnmng.onSelect = function() {
	fls = File(pP = app.document.presentationPath).getFiles(/\.jpg$/i), cde = ''
	while(fls.length) ((slc = (nme = (fle = fls.shift()).name).slice(0, 17)) != cde) &&
	(cde = slc, bdefgh = 'bdefgh'.split('')), (rslt = re()) && fle.rename(rslt)
}

 

2 replies

Kukurykus
Brainiac
November 26, 2021
function re() {
	return fle.path + '/' + decodeURI(fle.name)
	.replace(/ .+(?=\.jpg)/, '_' + (def.shift() || 'b'))
}

fle = File(Folder.desktop + '/1234567890123_000 ExampleNameRandom1.jpg')
def = 'def'.split(''); while(def.length) fle.copy(re()); fle.rename(re())
BoluomiAuthor
Known Participant
November 27, 2021

Hello Kukurykus,

 

Thanks for taking the time to write this out - I am certainly going to try to digest it but currently this is way more advance than my brain. I am not even sure where to begin in running this or implementing it as usable tool. I am currently doing my results using two different substitution strings, but was wondering if it was possible to do it in one go. Are we allowed to post sample videos or images?

BoluomiAuthor
Known Participant
December 4, 2021

Make sure the first part (to not be changed) of names of your (un)selected files are different:

 

function re() {
	rplcd = fle.path + '/' + decodeURI(nme = fle.name)
	.replace(/ .+(?=\.jpg)/, '_' + (def.shift() || 'b'))
	return File(rplcd).name != nme && rplcd
}

rnmng = new MenuElement('command', 'Batch Renaming',
'at the end of Thumbnail'), rnmng.onSelect = function() {
	fls = File(pP = (ad = app.document).presentationPath).getFiles(/\.jpg$/i); while(fls.length) {
		fle = fls.shift(), def = 'def'.split(''); while(def.length) (rslt = re()) && fle.copy(rslt);
		(rslt = re()) && fle.rename(rslt)
	}
}

 

If it works, due to your original request, close this topic by marking the solution as correct 😉


Hey there! 

It's not working but I think I should close this topic - since I did not offer enough explonation on it and might be causing confusion! Your code is really helpful for me to study what it is doing though! 

BoluomiAuthor
Known Participant
November 25, 2021

If its relevant the first 17 digits are always the same in the image batches - so batch 1 - will have the same 17 first digits then random digital counter, then batch 2 will have the same 17 first digits, etc. Only unique between batch of images.