Skip to main content
joshuab62404869
Participating Frequently
March 26, 2018
Answered

Script to duplicate and rename files

  • March 26, 2018
  • 1 reply
  • 3583 views

Hey guys,

I need to create a custom rename script that will duplicate selected files and remove some characters(could vary from 9 to 10) from the end of the name and replace it with 1

So it looks like this now :  NBSIACBGT-BKL-1 COPY.psd

And I need it like this : NBSIACBGT-1.psd

I already managed to do it through regular bridge using this regular expression :    .{9}(\..{1,})$  

I just need to add it into a script so I can call it out of a keyboard shortcut if that make sens to you guys.

Thank you !

This topic has been closed for replies.
Correct answer SuperMerlin

Would this work?

#target bridge  

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

var cSelected = new MenuElement("command", "Copy selected",  "at the end of Tools","cFiles");

}

cSelected.onSelect = function () {

var sels = app.document.selections;

var count = app.document.selectionsLength;

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

var newName =decodeURI(app.document.selections.spec.name).match(/[^-]*/);

var ext = decodeURI(app.document.selections.spec.name).match(/\..+$/);

app.document.selections.spec.copy(app.document.presentationPath+ "/" +newName+"-1"+ext);

    }

};

Stephen Marsh
Community Expert
Community Expert
March 27, 2018

Random thoughts…

How do you assign a keyboard shortcut to a script in Bridge?

As I can’t script, It would likely be quicker and easier for me to do this through the operating system rather than in Bridge. If this is something that you would like to try at the OS level rather than Bridge, what OS are you?

I am unsure of your regex, as you say it may need to remove between 9-10 characters from the end… What is the pattern of your filenames and is it consistent? Can you provide more than one example of varied filenames?

Would it simply be easier to work from the start and stop at the first hyphen character, if that matches the pattern (rather than work backwards by a variable amount)?

Find: (^.+?-)(.+?)(.[^\.]+$)

Replace: $1$3

or

Find: (^.+?-)(.+)

Replace: $1

EDIT: The following topic is also related to your post, however it was never answered –

Duplicate selected item and rename in a script.

joshuab62404869
Participating Frequently
March 28, 2018

Hi Stephen,

I'm working on Siera V 10.12.6

If I could have this procedure scripted under Tools in Bridge, I can go to System Preferences - Keyboard - Shortcuts - App shortcuts, and call my script from there...does that make sense ?

I just need to have this working in a script.

Something that would be like this :

- duplicate all the WHATEVERCODEIS-BL-1.psd / WHATEVERCODEIS-WH-1.psd / WHATEVERCODEIS-OR-1.psd

- delete everything till WHATEVERCODEIS- keeping the extension and the - after the code

- add an 1

Thank you !

SuperMerlin
SuperMerlinCorrect answer
Inspiring
March 28, 2018

Would this work?

#target bridge  

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

var cSelected = new MenuElement("command", "Copy selected",  "at the end of Tools","cFiles");

}

cSelected.onSelect = function () {

var sels = app.document.selections;

var count = app.document.selectionsLength;

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

var newName =decodeURI(app.document.selections.spec.name).match(/[^-]*/);

var ext = decodeURI(app.document.selections.spec.name).match(/\..+$/);

app.document.selections.spec.copy(app.document.presentationPath+ "/" +newName+"-1"+ext);

    }

};