• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Script to duplicate and rename files

Community Beginner ,
Mar 26, 2018 Mar 26, 2018

Copy link to clipboard

Copied

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 !

TOPICS
Scripting

Views

3.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Mar 28, 2018 Mar 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);

...

Votes

Translate

Translate
Community Expert ,
Mar 27, 2018 Mar 27, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 28, 2018 Mar 28, 2018

Copy link to clipboard

Copied

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 !

Untitled-1.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 28, 2018 Mar 28, 2018

Copy link to clipboard

Copied

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);

    }

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 28, 2018 Mar 28, 2018

Copy link to clipboard

Copied

As usual, great work SuperMerlin! I can’t believe it only took 13 lines of code, hah!

I hope that works for joshuab, I had my doubts about the filenames, usage etc…

Example, it is OK to run this on file LOMSPCHTJ-OR-1.psd – however what if it was run on file LOMSPCHTJ-OR-2.psd, it would create a duplicate as both files would be renamed to LOMSPCHTJ-1.psd! SuperMerlin has accounted for this in his script, however I would have thought that this command would potentially be used with multiple images, not just one.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 28, 2018 Mar 28, 2018

Copy link to clipboard

Copied

Fantastic ! It's exactly what I was looking for .

Works perfect on single and multiple files.

I guess  I have to start learning javascript. Can you guys give me some tips where to start ?

Thank you very much SuperMerlin !

Greetings from Germany

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 29, 2018 Mar 29, 2018

Copy link to clipboard

Copied

LATEST

You could download and install Adobe ExtendScript Toolkit

https://helpx.adobe.com/creative-cloud/kb/creative-cloud-apps-download.html

This is the development enviroment tool.

In the help section you will find the JavaScript Tools Guide pdf

Also download the Software Development Kits where you will find more documentation and examples.

Bridge SDK

https://console.adobe.io/downloads/br

Photoshop SDK

https://www.adobe.com/devnet/photoshop/sdk.html

Then there are the forums, if you can't find an answer ask, you will get a lot of help.

https://forums.adobe.com/community/photoshop/photoshop_scripting/content

https://forums.adobe.com/community/bridge/bridge_scripting/content

Good luck!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines