Copy link to clipboard
Copied
I have lots of images with file names like this, Jaroslav_Krej%C4%8D%C3%AD.jpg,
I am trying to copy the file name to the image caption.
Is there a way to do this and replace the special characters with their correct ones and can i do this in a batch.
I'm very new to this and its driving me crazy
Thanks very very much in advance
Okey, later when I remove bugs we'll do easy test to see any menu loaded to Bridge is present at it's place...
EDIT:
Save it as Item.jsx on your (& run from) desktop (paste to noteapd & then saving insert a name into dbl quotes: "Item.jsx"):
#target bridge
new MenuElement("command", "Item", "at the end of Thumbnail")
When you click with right mouse button on any folder/file or even outside in the 'Content' area you will see a list of default items (commands) starting with "Open" and then other like "
...Copy link to clipboard
Copied
See the answer in this thread...
Copy link to clipboard
Copied
paulf58498760 you mention the “caption” metadata field, which is actually a legacy label, this is currently known as “description”. The topic thread that SuperMerlin pointed you to is labeled “title”, however the actual metadata field that the script populates is the “description”.
This script only removes the filename extension… However you also mention other special characters that need to be removed, so two questions:
1) Which special characters? Is it just the underscore _ and only the percentage sign % or is it also the letter and digit with the % sign? Can you provide samples of more than one filename and the required result so that the forum can be sure that the pattern is consistent?
Jaroslav_Krej%C4%8D%C3%AD.jpg
Jaroslav Krej C4 8D C3 AD
Jaroslav Krej
2) Do you also wish to remove the special characters from the filename, or leave the filename alone and only remove the special characters from the description metadata field?
Copy link to clipboard
Copied
Thanks for the replys
Yes sorry the Description field is where I'm trying to move the data.
I'm trying to convert the special characters as per the link bellow and the examples after, yes I want to swap the underscore for a space and remove the .jpeg bit.
http://www.fileformat.info/info/charset/UTF-8/list.htm
Before and after examples :-
Marie_Sklodowska,_%C3%A9tudiante,_en_1895.jpg - Marie Sklodowska, étudiante, en_1895
Miko%C5%82aj_Rey.jpg - Mikołaj Rey
Some file names have more than 1 group of special characters.
I hope this helps.
Again thanks very much for all your help
Copy link to clipboard
Copied
Copy it to Adobe Startup Scripts folder, so 'C:\Program Files\Common Files\Adobe\Startup Scripts CS6\Adobe Bridge' (in case of Ps CS6), and then reopen Bridge. Right click on the folder containing (subfolder with) images where (some) have wrong names and select last time from the commands list: "Name to Caption". Aditionally all your encoded file names are going to get decoded! This functionallity will be always available in your Bridge as far as you keep the Name to Caption.jsx script in mentioned folder.
#target bridge
NtC = new MenuElement("command", "Name to Caption", "at the end of Thumbnail")
NtC.onSelect = function() {
function FSf(sF, dst, i) {
function io(v) {return v instanceof Folder}
if (fld = io(sF)) sF = sF.getFiles()
for(; i < sF.length; i++) {
if (io(fof = sF)) dst.push(fof.name), FSf(fof, dst, 0)
else if(/.jpg$/i.test(fof)) {
(md = new Thumbnail(fof).synchronousMetadata)
.namespace = 'http://ns.adobe.com/photoshop/1.0/'
md.Caption = (nme = decodeURI(decodeURI(fof.name)))
.slice(0, -4); if(!(nme == fof.name)) sF.rename(nme)
}
}
return dst
}
FSf(app.document.selections[0].spec, [], 0).join('\n')
}
Btw there are 2 bugs (when you don't click on folders and that sometimes renaming may work too fast) later I'll fix.
Copy link to clipboard
Copied
Hi, Thanks for the script but i'm getting an error.
Copy link to clipboard
Copied
Later I changed code I posted originally but I see you used that previous. You can remove white spaces characters which are after slash '\' and then save code again or just use newer one with corrected part. But the best will be if you copy a code you have in my previous post. Remember there are 2 bugs later I'll fix. It's not hard, but I'm at work right now.
NtC = new MenuElement("command", "Name to Caption", "at the end of Thumbnail")
Copy link to clipboard
Copied
Hi,
Thanks again, script loads but I right click on folder but it does not show any option to use the script
Copy link to clipboard
Copied
Okey, later when I remove bugs we'll do easy test to see any menu loaded to Bridge is present at it's place...
EDIT:
Save it as Item.jsx on your (& run from) desktop (paste to noteapd & then saving insert a name into dbl quotes: "Item.jsx"):
#target bridge
new MenuElement("command", "Item", "at the end of Thumbnail")
When you click with right mouse button on any folder/file or even outside in the 'Content' area you will see a list of default items (commands) starting with "Open" and then other like "Paste", "Cut" etc. At the bottom of this list you should see new item, named "Item". I checked 2018 Bridge documentation and menu / commands section is alike CS 6 version. Perhaps you must allow this script to be loaded each time at start of Bridge. Edit/Preferences/StartupScripts. Then find checkbox for Item and check it (don't forget to tell me that was there in case script still won't be working). Then reopen Br and script should be loaded. If not, check again that SS section. If there is not script listed then maybe it's not in proper Startup Scripts folder. But if you copied before it to in and then at startup of Bridge you got that error you posted a screen of it means Br detected this script for sure inside a folder that should be put in. Anyway, below is the newest VERSION II of script for you:
#target bridge
NtC = new MenuElement("command", "Name \
to Caption", "at the end of Thumbnail")
NtC.onSelect = function() {
function rec(sF, dst, i) {
if (fld = io(sF)) sF = sF.getFiles(); for(; i < sF.length; i++) {
if (io(fof = sF)) dst.push(fof.name), rec(fof, dst, 0)
else if(/.jpg$/i.test(fof)) {
function reg(v) {return v.replace(/_/g, ' ')}
ns = 'http://ns.adobe.com/photoshop/1.0/';
(md = new Thumbnail(fof).synchronousMetadata).namespace = ns
md.Caption = (spc = reg((nme = decodeURI(dec = decodeURI(fn = fof.name))))).slice(0, -4)
I = 0; while(nme != dec && fn == fof.name && I < 5) $.sleep(50), I += !fof.rename(spc)
}
}
return dst
}
function io(v) {return v instanceof Folder}
if ((sel = app.document.selections[0])
&& io(spec = sel.spec)) rec(spec, [], 0)
}
When you copy it to notepad DON'T FORGET to remove additional white spaces from after slash at end of second line!
This script browses entire content of selected folder, so all deepest nasted subfolders with all jpg images. Do not select more folders at once however only (first ?) one will be processed. It adds to description field name of file without extension, and change name of file to decoded. Both, that field and name of each file gets new name, where underscores are replaced with spaces, while all URL characters decoded. When in the same folder there is already a file with a desired name for source file then source one won't be changed to new version. It only will get new name in description field.
I tested it on hundrets files with different names and several folders, also with desired names for source files in range of one folder, and it worked well. You had to wait approximately about 10 mins with frozen Bridge if you ran process for 6000 files.
Even if you had only to change every file to the same name (however you can't have in the same folder same named files) and then quickly opened metadata panel to paste that name in as well, you'd spend about 15 hours working with very rapid tempo, and without making even one second breaks.
If you had additionally to change names to decoded ones by some application translator (where you put encoded name to get decoded) then again pasted it to file and description field that had to take 30 hours. Doing it totally manually (having in brain all URI codes with their equivalents) probably 50 hours. When checking each URI character in dictionary before you remember them all meantime that could be 120 hours so about 5 days (including nights), and all without eating, sleeping and geting up from a chair, with hands constantly having on keyboard while head directed to buring your eyes screen
Copy link to clipboard
Copied
That is some kind of sweet voodoo Kukurykus!
I am not sure if paulf58498760 wishes to have the filenames changed or not… Obviously making a change to the script would be ideal if the filename was not to be changed, however I can offer a short term alternative… Before running the script on a folder using the contextual menu command, one can use the Batch Rename Tool in Bridge to write the filename to the preserved filename metadata field, then after running the script, one can then restore the preserved filename.
Copy link to clipboard
Copied
This is awesome, i've checked on a few files and it seems to be working, it is missing some files and not converting others. I'll have an experiment and get back to you.
BUT THANK YOU VERY VERY MUCH
Copy link to clipboard
Copied
I'm seeing you answer for Stephen_A_Marsh post, but it seems like you comment a script I wrote.
Anyway, I found another 2 bad behaviours I'm going to fix:
I'm going also to expand script of eventuality an user wants to select more than one main folder, as if their parent folder was selected then all subfolders would be processed while someone wants only choosen ones were.
Copy link to clipboard
Copied
Fantastic, I’m very grateful for all your help
Copy link to clipboard
Copied
If someone wants to only put file name without extension to description field there's need to comment 19th line:
// I = 0; while(nme != dec && fn == fof.name && I < 5) $.sleep(50), I += !fof.rename(spc)
If that has to be name with extension in description field then there's also need to remove ".slice(0, -4)" in 18th line:
md.Caption = (spc = reg((nme = decodeURI(dec = decodeURI(fn = fof.name)))))
Interested person can change only line 18th without 19th to have renamed files & extension in description field.
I didn't know that thing with preserved names. When I write scripts I do something similar when I want to retrieve original file name or use it later for something else. I store it in one of unused yet meta fields. However you have to have scripting expeience for it, while Batch help you without this knowledge. The only limitation I see is that you can preserve one file at time, or I'm wrong? Can be it automated somehow for all other filies at least in the same folder? Rather not. Too bad as it's not hard to implement even for one month experience amatour of scripting.
I wonder why do you avail people on this forum from a longer time using other methods which are simple and understable (what's good) and works after all. It seems you could be good scripter with your passion, and I'm not saying about graphics programming in Photoshop but maintaining System File and Folder operations. So something you are helping others with and there's no chance to avoid it in any script working for more than one image.
Copy link to clipboard
Copied
The script has stopped working, I can't see a reason for this ?
Copy link to clipboard
Copied
Ps. please tell me meantime what files a script is missing and which ones doesn't convert. Give me samples, some short list of those files, examples for two events you mentioned, so I can see what could go wrong. As you guess only users can find bugs a creator was not aware they can happen, so predict / imagine all possible specific situtations to avoid all of them.
Copy link to clipboard
Copied
Just run a test on a few files these did not convert
Sheep_Camp%2C_Chilkoot_Pass%2C_Alaska_April_1898_%28HEGG_660%29.jpeg
Sheep_Creek%2C_now_named_Thane%2C_on_Gastineau_Channel%2C_Alaska%2C_nd_%28NOWELL_29%29.jpeg
These ones the filename didn’t change but the file name was moved to the description and converted, Further checking results if a file that can’t be converted is in a folder with files that can be converted it does not convert, if I take the troublesome file out the conversion is done on the other files
%C3%8Dcaro._Ilustraci%C3%B3n_de_%22La_corte_de_Carlos_IV%22_de_Gald%C3%B3s.jpg
%22A_Beckoning_Vista%22%2C_Stanley_Park%2C_Vancouver%2C_B.C..jpg
I have to pop out for a while I hope this helps
Thanks. Paul
Copy link to clipboard
Copied
Sheep_Camp%2C_Chilkoot_Pass%2C_Alaska_April_1898_%28HEGG_660%29.jpeg
Sheep_Creek%2C_now_named_Thane%2C_on_Gastineau_Channel%2C_Alaska%2C_nd_%28NOWELL_29%29.jpe g
It didn't convert 2 first files because of their extended extension. Normally it checked only .jpg files, while they were .jpeg's. I think you did mistake in case of second file as there is .jpe g (space inside) or that file was named so in fact?
%C3%8Dcaro._Ilustraci%C3%B3n_de_%22La_corte_de_Carlos_IV%22_de_Gald%C3%B3s.jpg
%22A_Beckoning_Vista%22%2C_Stanley_Park%2C_Vancouver%2C_B.C..jpg
Next 2 files after decoding got double quotes, special characters there are not allowed in names of files. It's why they couldn't be renamed. I did workaround and now all files with double quotes are converted to their normal names but reaplacing double quotes with single ones.
I also fixed bugs I mentioned before and added possibility to select more than one parent folder. Here is VERSION III:
#target bridge
NtC = new MenuElement('command', 'Name to Caption', 'at the end of Thumbnail')
NtC.onSelect = function() {
function rec(sF, dst, i) {
if (fld = io(sF)) sF = sF.getFiles(); for(; i < sF.length; i++) {
if (io(fof = sF)) dst.push(fof.name), rec(fof, dst, 0)
else if((r = /.jpe?g$/i).test(fof)) {
ns = 'http://ns.adobe.com/photoshop/1.0/'
function jpg(v) {return v.replace(/jpeg/, 'jpg')} function reg(v) {return v
.replace(/[_"]/g, function(_, v1, v2) {return v2[v1] == '_' ?' ' : '\''})}
(md = new Thumbnail(fof).synchronousMetadata).namespace = ns, itrt = 0
md.Caption = (nme = reg(decodeURI(dec = decodeURI(fn = fof.name)))).split(r)[0]
while(nme!=dec&&fn==fof.name&&itrt<5)$.sleep(150),itrt+=!fof.rename(e = jpg(nme))
if (itrt > 4) RegExp(nme).test(String(Array().slice.call(sF))), fof.rename('D_' + e)
}
}
return dst
}
function io(v) {return v instanceof Folder}
if (len = (sel = (ad = app.document).selections).length) {
for(h = 0; h < len; h++) if (io(spec = sel
.spec)) rec(spec, [], 0) }
}
it changes UTF-8 characters in file names to ASCII characters, it also saves changed file name (without extension) to Description field in file metadata.
Copy it to Adobe Startup Scripts folder, so 'C:\Program Files\Common Files\Adobe\Startup Scripts CS6\Adobe Bridge' (in case of Ps CS6), and then reopen Bridge. Right click on the folders containing (subfolder with) images where (some) have wrong names and select last item from the commands list: "Name to Caption". Aditionally all your encoded file names are going to get decoded! This functionallity will be always available in your Bridge as far as you keep the Name to Caption.jsx script in mentioned folder.
If the 'Name to Caption' item won't be at its place then go to Edit/Preferences/StartupScripts. Then find checkbox with item name and check it. Reopen Bridge and script should be loaded.
Copy link to clipboard
Copied
OK I have a few more that stop the script. It's working much better but still needs some tweaks, thanks for all your work.
Here are the ones that are causing problems, If I find more I'll post them.
HUTS_AND_HOUSES_ON_DIZENGOFF_STREET_IN_TEL_AVIV._%D7%91%D7%AA%D7%99%D7%9D_%D7%95%D7%A6%D7%A8%D7%99%D7%A4%D7%99%D7%9D_%D7%91%D7%A8%D7%97%D7%95%D7%91_%D7%93%D7%99%D7%96%D7%99%D7%A0%D7%92%D7%95%D7%A3_%D7%91%D7%AA%D7%9C_%_0064.jpg
HYDRAULIC_PRESS_FOR_THE_TESTING_OF_BUILDING_MATERIALS_AT_THE_HAIFA_TECHNION._%D7%94%D7%9E%D7%A2%D7%91%D7%93%D7%94_%D7%9C%D7%94%D7%A0%D7%93%D7%A1%D7%94_%D7%91%D7%98%D7%9B%D7%A0%D7%99%D7%95%D7%9F_%D7%91%D7%97%D7%99%D7%A_0067.jpg
JUICE_VENDOR_ON_THE_BEACH_OF_TEL_AVIV._%D7%9E%D7%95%D7%9B%D7%A8_%D7%9E%D7%99%D7%A6%D7%99%D7%9D_%D7%A9%D7%9C_%22%D7%A2%D7%A1%D7%99%D7%A1%22_%D7%91%D7%97%D7%95%D7%A3_%D7%94%D7%99%D7%9D_%D7%A9%D7%9C_%D7%AA%D7%9C_%D7%90%D_0035.jpg
JUNIOR_MEMBERS_OF_THE_HAPOEL_SPORTS_ORGANIZATION_PERFORMING_GYMNASTICS_AT_THE_STADIUM_DURING_THE_WORKERS'_SPORTS_RALLY_IN_TEL_AVIV._%D7%99%D7%9C%D7%93%D7%99%D7%9D_%D7%9E%D7%91%D7%A6%D7%A2%D7%99%D7%9D_%D7%AA%D7%A8%D7%9_0043.jpg
K_B_Jir%C3%A1k_1929.jpg
ZION_GATE_IN_THE_OLD_CITY_OF_JERUSALEM._(COURTESY_OF_AMERICAN_COLONY)_%D7%A9%D7%A2%D7%A8_%D7%A6%D7%99%D7%95%D7%9F_%D7%91%D7%A2%D7%99%D7%A8_%D7%94%D7%A2%D7%AA%D7%99%D7%A7%D7%94_%D7%91%D7%99%D7%A8%D7%95%D7%A9%D7%9C%D7%9_0123.jpg
Copy link to clipboard
Copied
Item 1, 2, 3, 4, 6: the problem is last PERCENT character (with following single letter/diggit if exists). It can't be decoded as far it doesn't appear as %25. Because there is double decoding needed for whole file name % character it should be encoded even twice to be as: %2525. That's not hard to detect it by regex using /%(?![a-z\d]{2})/ig code and then 2 times encode this component before whole file name will be double decoded. Unfortunately it makes problems. Sometimes PERCENT character (even previously two times encoded) doen't change final file name, but mostly it change order of parts of name, so some that is at beginning for some reason goes after PERCENT character and that was after goes before. Additionally when that happens, sometimes there is even added special character after a digit that is staying after PERCENT character.
So the conclusion is that best way is to remove all sinlge PERCENTES characters (with/out following letter/digit). I assume perhaps these file names wre longer originally but that coused some too long part were simply cut(?). It's why you can't keep original names as whole. I don't know but probably all you need is to restore original look of file names as much as possible to make it readable, while that there will be removed something what is not important doesn't make difference.
There were two spaces at different positions in middle of those file names, but I guess they were created during pasting. As to item 5, there is no problem.
Well, I use that regex I mentioned to remove single PERCENTEGES characters with following single digit/letter if occurs.
Copy link to clipboard
Copied
Would there be less problems if the file name was left alone and the conversion process only taking place in the description field ? this would work for me
Copy link to clipboard
Copied
You won't lose much. For example when there is _%_0064.jpg, %A_0067.jpg, %D_0035.jpg, %9_0043.jpg and %9_0123.jpg you will get: __0064.jpg, _0067.jpg, _0035.jpg, _0043.jpg, _0123.jpg or else the same but with those single digit / letter from after percent character. After all the same result will be in description field as there is no difference a file name is decoded to be renamed or just some text as a string. In both cases an error is occuring. All from before % char will be converted as well.
So are you fine with removing from original names only that last % character (together or not with following letter / digit)?
Copy link to clipboard
Copied
Yes this will be fine, will the script do this or do I have to remove them with another method, i'm new to scrips so I'm just about keeping up !!!!
Copy link to clipboard
Copied
Script will do it when I add this functionality to. So just wait it will be ready.
Copy link to clipboard
Copied
That is awesome, I’m so thankful for your help