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

Copy Filename to Keyword

Community Beginner ,
Apr 18, 2023 Apr 18, 2023

Hi all,

 

I am looking for a script to copy filename to keyword in Bridge. So far I have found this which runs well for title (http://kasyan.ho.ua/bridge/add_filename_to_description-title.html) but I really need the copy to be in the keyword field. Could it be possible to edit this script to suit my needs?

 

I've not got much experience with Javascript so any help would be much appreciated. 

 

macOS 12.4, Bridge 13.0.3

 

Thanks 

Ollie

 

TOPICS
How to , Keywords
1.3K
Translate
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

Community Expert , Apr 18, 2023 Apr 18, 2023

A couple of scripts from my archive, not tested in Bridge 2023...

 

// https://forums.adobe.com/thread/656144
// https://forums.adobe.com/message/9744916
// https://forums.adobe.com/message/9745231
#target bridge
addNametoMeta = {};
addNametoMeta.execute = function(){
  var sels = app.document.selections;
  for (var i = 0; i < sels.length; i++){
var md = sels[i].synchronousMetadata;
    md.namespace = "http://ns.adobe.com/photoshop/1.0/";
    var Name = decodeURI(sels[i].name).replace(/\.[^\.]+$
...
Translate
Community Expert ,
Apr 18, 2023 Apr 18, 2023

A couple of scripts from my archive, not tested in Bridge 2023...

 

// https://forums.adobe.com/thread/656144
// https://forums.adobe.com/message/9744916
// https://forums.adobe.com/message/9745231
#target bridge
addNametoMeta = {};
addNametoMeta.execute = function(){
  var sels = app.document.selections;
  for (var i = 0; i < sels.length; i++){
var md = sels[i].synchronousMetadata;
    md.namespace = "http://ns.adobe.com/photoshop/1.0/";
    var Name = decodeURI(sels[i].name).replace(/\.[^\.]+$|_/g, ' '); //remove extension | globally remove underscores 
    md.Keywords = md.Keywords + ";" + Name;
  }
}
if (BridgeTalk.appName == "bridge"){
var menu = MenuElement.create( "command", "Filename to Keywords - Removing Underscore", "at the end of Tools");
  menu.onSelect = addNametoMeta.execute;
}

 

 

// https://forums.adobe.com/thread/656144
#target bridge   
addNametoMeta = {};   
addNametoMeta.execute = function(){   
  var sels = app.document.selections;   
  for (var i = 0; i < sels.length; i++){   
var md = sels[i].synchronousMetadata;   
    md.namespace = "http://ns.adobe.com/photoshop/1.0/";   
    var Name = decodeURI(sels[i].name).replace(/\.[^\.]+$/, '');  
    md.Keywords = md.Keywords + ";" + Name;   
  }   
}   
if (BridgeTalk.appName == "bridge"){   
var menu = MenuElement.create( "command", "Save Filename in Keywords", "at the end of Tools");   
  menu.onSelect = addNametoMeta.execute;   
}  

 

The following does work in Bridge 2023:

// https://forums.adobe.com/thread/656144
#target bridge
addNametoMeta = {};
addNametoMeta.execute = function () {
  var sels = app.document.selections;
  for (var i = 0; i < sels.length; i++) {
    var md = sels[i].synchronousMetadata;
    md.namespace = "http://ns.adobe.com/photoshop/1.0/";
    var Name = decodeURI(sels[i].name).replace(/\.[^\.]+$/, '');
    md.Keywords = md.Keywords + ";" + Name;
  }
}
if (BridgeTalk.appName == "bridge") {
  var menu = MenuElement.create("command", "Filename to Keywords", "at the end of Tools");
  menu.onSelect = addNametoMeta.execute;
}  

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

Translate
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 ,
Apr 18, 2023 Apr 18, 2023

This one sets the filename in the preserved filename metadata (the same field used by Batch Rename):

 

// https://forums.adobe.com/thread/656144
// https://forums.adobe.com/message/9498691
#target bridge
addNametoMeta = {};
addNametoMeta.execute = function(){
  var sels = app.document.selections;
  for (var i = 0; i < sels.length; i++){
var md = sels[i].synchronousMetadata;
    md.namespace = "http://ns.adobe.com/xap/1.0/mm/";
    var Name = decodeURI(sels[i].name).replace(/\.[^\.]+$/, '');
    md.PreservedFileName = md.PreservedFileName + Name;
  }
}
if (BridgeTalk.appName == "bridge"){
var menu = MenuElement.create( "command", "Save Filename in PreservedFileName metadata", "at the end of Tools");
  menu.onSelect = addNametoMeta.execute;
}
Translate
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 ,
Apr 18, 2023 Apr 18, 2023

I appreciate your help, I've now got it working! My current filenames are in the following structure

 

1999.326.6-O.tif

1998.500.5-R.tif

 

Do you know if it would be possible to run the same script but to remove everything after and including the hyphon (-), so in this instance the keywords would then simply read 1998.500.5.tif and 1998.500.5.tif?

 

Really appreciate your help with this!

 

 

Translate
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 ,
Apr 18, 2023 Apr 18, 2023

Try changing the following line from:

 

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

 

To:

 

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

 

If you don't want the filename extension, just remove the regular expression $3 capture group backreference.

 

Translate
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 ,
Apr 20, 2023 Apr 20, 2023

That's working well, thanks a lot for your help!

 

Translate
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 ,
May 31, 2023 May 31, 2023

This script has been proving incredibly useful, so thanks a lot for that.

 

I wonder if you could help with one more edit. Occasionally, my filenames are titled as follows:

2022.1.100 (reverse)-R.tif

In this instance, I would like the action to remove everything after the space, so that all is left is 2022.1.100 but to also keep the original functionality which means a filename such as:

2022.1.100-R.tif 

also becomes 2022.1.100 (so that everything after the dash (-) is removed). In all instances it will be either a (-) or a space, as well as subsequent text is removed.

 

I would be grateful for any assistance with this! Do let me know if I can make it clearer.

As a reminder, I am currently using the following JS:

 

#target bridge
addNametoMeta = {};
addNametoMeta.execute = function () {
var sels = app.document.selections;
for (var i = 0; i < sels.length; i++) {
var md = sels[i].synchronousMetadata;
md.namespace = "http://ns.adobe.com/photoshop/1.0/";
var Name = decodeURI(sels[i].name).replace(/(^.+)(-.+)(\.[^\.]+$)/, '$1');
md.Keywords = md.Keywords + ";" + Name;
}
}
if (BridgeTalk.appName == "bridge") {
var menu = MenuElement.create("command", "Filename to Keywords", "at the end of Tools");
menu.onSelect = addNametoMeta.execute;
};

Translate
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 ,
May 31, 2023 May 31, 2023
quote

In all instances it will be either a (-) or a space, as well as subsequent text is removed.

 

By @ollie29445712d6e3



 

Please try changing the following line from:

 

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

 

To this:

 

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

 

Let me know how you go!

Translate
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 ,
Jun 01, 2023 Jun 01, 2023

Thanks a lot! Unfortunately, it still seems to be retaining the text immediately following the space, so where the filename is originally:

 

2022.1.100 (reverse)-R

 

Changing the line you suggest copies the following to Keyword:

 

2022.1.100 (reverse)

 

As opposed to simply:

 

2022.1.100

Translate
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 ,
Jun 01, 2023 Jun 01, 2023

@ollie29445712d6e3 â€“ Sorry about that, I have tested the following with success:

 

var Name = decodeURI(sels[i].name).replace(/(^.+?)( .+|-.+)(\.[^\.]+$)/g, '$1');

 

 

Translate
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 ,
Jun 01, 2023 Jun 01, 2023

That works perfectly, thanks again for your help!

Translate
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 ,
Jun 01, 2023 Jun 01, 2023

You're welecome!

Translate
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 ,
Jul 13, 2023 Jul 13, 2023

Hi again!

 

Do you think, as one final edit, it might be possible for this script to action the following file structure:

2022.1.1.tif or 2022.1.1.jpg, so that in either instance the Keyword becomes 2022.1.1 alongside the previous edits?

 

I understand this might be trickier as the reference point is simply the last . or ".tif"/".jpg" so I wasn't sure if it would be possible?


Best wishes,

Ollie

 

Translate
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 ,
Jul 13, 2023 Jul 13, 2023

@ollie29445712d6e3 

 

So is it just that the final 2 digits before the file extension should be removed? 

Translate
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 ,
Jul 13, 2023 Jul 13, 2023

As a summary, it is anything that comes after the final number of the file name that needs removing.

 

So:

 

2022.1.1.tif

2022.1.1-R.tif

2022.1.1.1_O.tif

2022.1.1 (reverse).jpg

 

In all of these instances, the only part of the filename that should be copied to Keyword is "2022.1.1".

 

Hope that helps clear things up.

 

 

Translate
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 ,
Jul 13, 2023 Jul 13, 2023
LATEST

@ollie29445712d6e3 â€“ So retain the pattern of:

 

Four digits, period, digit, period, digit

 

/* 
Specific Filename Pattern to Keywords 2023.jsx
https://community.adobe.com/t5/bridge-discussions/copy-filename-to-keyword/m-p/13933675 
*/

#target bridge

addNametoMeta = {};
addNametoMeta.execute = function () {
  var sels = app.document.selections;
  for (var i = 0; i < sels.length; i++) {
    var md = sels[i].synchronousMetadata;
    md.namespace = "http://ns.adobe.com/photoshop/1.0/";
    // four digits, period, digit, period, digit
    var Name = decodeURI(sels[i].name).replace(/(^\d{4}\.\d\.\d)(.+$)/, '$1');
    md.Keywords = md.Keywords + ";" + Name;
  }
}
if (BridgeTalk.appName == "bridge") {
  var menu = MenuElement.create("command", "Specific Filename Pattern to Keywords 2023", "at the end of Tools");
  menu.onSelect = addNametoMeta.execute;
}  

 

  

Translate
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 ,
Apr 18, 2023 Apr 18, 2023

That's brilliant, thanks a lot. Although

I'm having trouble getting the script into Bridge. I have followed the instructions on the link you attached here but after I leave the file in the Startup Script folder there is no pop-up that appears on Bridge allowing me to select 'Yes' to enable the script. Any thoughts? Images attached below...

 

Screenshot 2023-04-18 at 15.23.22.png

 

Screenshot 2023-04-18 at 15.24.09.png

 

Translate
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