Copy link to clipboard
Copied
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
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(/\.[^\.]+$
...
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
That's working well, thanks a lot for your help!
Copy link to clipboard
Copied
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;
};
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
@ollie29445712d6e3 – Sorry about that, I have tested the following with success:
var Name = decodeURI(sels[i].name).replace(/(^.+?)( .+|-.+)(\.[^\.]+$)/g, '$1');
Copy link to clipboard
Copied
That works perfectly, thanks again for your help!
Copy link to clipboard
Copied
You're welecome!
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
So is it just that the final 2 digits before the file extension should be removed?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
@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;
}
Copy link to clipboard
Copied
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...
Find more inspiration, events, and resources on the new Adobe Community
Explore Now