Copy link to clipboard
Copied
The version of Bridge that I'm using has a bug that reverses the order of the images when I import them. I'm trying to write a extendscript to reverse the order of the images by renaming them. For example if I import five images, image one needs to be renamed image five and image two needs to be renamed image four etc. The problen seems to be my standard filenaming format: ©_Stan_Tess_20220516_0005.ARW. If I remove the © symbol I can rename the file but not with the symbol. If I use Batch Rename... within Bridge I can add the © symbol but I would like to do it in the script. Thanks!
#target bridge
if(BridgeTalk.appName == 'bridge'){
try{
//create menu
var cpPath = MenuElement.create('command', 'Image Order Fix', 'at the end of Tools');
var ftcpPath = MenuElement.create('command', 'Image Order Fix', 'after Thumbnail/Open', this.menuID); //add to Contextual menu
cpPath.onSelect = function(){
ImageOrderFix();
}
ftcpPath.onSelect = function(){
ImageOrderFix();
}
function ImageOrderFix(){
var thumbs = app.document.selections;
var selectedFile = new Thumbnail(thumbs[0]);
MyFolder = decodeURI(selectedFile.spec.parent.toString());
var folder = Folder(MyFolder);
var files = folder.getFiles();
var file, extension, baseName, rename;
for(var i = 1; i < files.length; i++){
file= files[i];
extension = files[i].name.slice(files[i].name.length-4, files[i].length);
baseName =files[i].name.slice(6, files[i].name.length-8);
rename= ((files.length) -i ).toString();
switch(rename.length.toString() ) {
case "1":
rename= "000" + rename
break;
case "2":
rename= "00" + rename
break;
case "3":
rename= "0" + rename
break;
case "4":
//~ rename = rename
break;
}
rename = baseName +rename +extension
//~ file.rename(rename);
file.rename( "©" + rename);
//~ file.rename( String.fromCharCode(169) +rename);
}
}
}
catch(e){
alert(e + ' ' + e.line);
}
}
There's definitely something weird with "©_" on Windows.
This is a workaround so I'm not confident recommending it, but I was able to rename using "©X_" and then rename again removing the "X".
Also, I had to change your loop to begin at 0 to get all the files to rename:
for(var i = 0; i < files.length; i++){
#target bridge
if(BridgeTalk.appName == 'bridge'){
try{
//create menu
var cpPath = MenuElement.create('command', 'Image Order Fix', 'at the end of Tools');
var ftcpPath = MenuElement.cre
...
Copy link to clipboard
Copied
I haven't had time to test, however, I'd suggest that you try to use the code instead:
\xA9
https://charbase.com/00a9-unicode-copyright-sign
Copy link to clipboard
Copied
Hi, Thanks, I missed that one in my search but unfortunately "\xa9" doesn't work either. I had previously tried String.fromCharCode(169) and "\©" before but they also didn't work.
Copy link to clipboard
Copied
Are you using Windows?
I'm on a Mac and the © symbol worked for me in Bridge 2022.
Copy link to clipboard
Copied
Yes I'm on Win 11 and Bridge 2022 but I also have Bridge CS6. CS6 doesn't like the code either.
Copy link to clipboard
Copied
I just tested it on Win 10 & Bridge CS6 and that too is a no go.
Copy link to clipboard
Copied
I'm on Windows 10 as well.
I canot figure this out. Wierdly, if I add a character afert the ©, it works, i.e. file.rename( "©_"+rename)
I've tried removing the leading underscore from baseName and then using file.rename( "©_"+rename), but that doesn't work.
Copy link to clipboard
Copied
That is bizarre. I just tried removing "_Stan_" from baseName and then using file.rename( "©_Stan_"+rename), but that doesn't work either. I also tried adding a second _ to file.rename( "©__Stan_"+rename) and that works but it's not in my naming convention. Then I tried file.rename( "b©_Stan_" + rename) and that works as well and so does file.rename( "©Stan_" + rename). I then added "Stan_" back to baseName and then used file.rename( "©\_" + rename) Which works but screwed up my i incrementor. I'll see if I can figure that out in the morning. It seems the problem is the "©_" combination and a way to escape it.
Copy link to clipboard
Copied
There's definitely something weird with "©_" on Windows.
This is a workaround so I'm not confident recommending it, but I was able to rename using "©X_" and then rename again removing the "X".
Also, I had to change your loop to begin at 0 to get all the files to rename:
for(var i = 0; i < files.length; i++){
#target bridge
if(BridgeTalk.appName == 'bridge'){
try{
//create menu
var cpPath = MenuElement.create('command', 'Image Order Fix', 'at the end of Tools');
var ftcpPath = MenuElement.create('command', 'Image Order Fix', 'after Thumbnail/Open', this.menuID); //add to Contextual menu
cpPath.onSelect = function(){
ImageOrderFix();
}
ftcpPath.onSelect = function(){
ImageOrderFix();
}
function ImageOrderFix(){
var thumbs = app.document.selections;
var selectedFile = new Thumbnail(thumbs[0]);
MyFolder = decodeURI(selectedFile.spec.parent.toString());
var folder = Folder(MyFolder);
var files = folder.getFiles();
var file, extension, baseName, rename;
for(var i = 0; i < files.length; i++){
file= files[i];
// ©_Stan_Tess_20220516_0005
// %C2%A9_Stan_Tess_20220516_0005.jpg
extension = files[i].name.slice(files[i].name.length-4, files[i].length);
baseName =files[i].name.slice(6, files[i].name.length-8);
rename= ((files.length) -i ).toString();
switch(rename.length.toString() ) {
case "1":
rename= "000" + rename
break;
case "2":
rename= "00" + rename
break;
case "3":
rename= "0" + rename
break;
case "4":
//~ rename = rename
break;
}
rename = baseName +rename +extension
//~ file.rename(rename);
file.rename( "©X"+rename);
//~ file.rename( String.fromCharCode(169) +rename);
}
for(var ii = 0; ii < files.length; ii++){
file= files[ii];
rename2 = files[ii].name.split("X_").join("_")
file.rename(rename2);
}
}
}
catch(e){
alert(e + ' ' + e.line);
}
}
Copy link to clipboard
Copied
Thanks, your solution works. I came up with a very simular approach except I don't add anything extra and remove it later. For some reason how I do the rename screwed with the i incrementor. That's why I changed to start with 1 but now I too had to change back to 0.
#target bridge
if(BridgeTalk.appName == 'bridge'){
try{
//create menu
var cpPath = MenuElement.create('command', 'Image Order Fix', 'at the end of Tools');
var ftcpPath = MenuElement.create('command', 'Image Order Fix', 'after Thumbnail/Open', this.menuID); //add to Contextual menu
cpPath.onSelect = function(){
ImageOrderFix();
}
ftcpPath.onSelect = function(){
ImageOrderFix();
}
function ImageOrderFix(){
var thumbs = app.document.selections;
var selectedFile = new Thumbnail(thumbs[0]);
var folder = Folder(decodeURI(selectedFile.spec.parent.toString()));
var files = folder.getFiles();
var file, extension, baseName, rename;
for(var i = 0; i < files.length; i++){
file= files[i];
extension = files[i].name.slice(files[i].name.length-4, files[i].length);
baseName =files[i].name.slice(7, files[i].name.length-8);
rename= ((files.length) -i ).toString();
switch(rename.length.toString() ) {
case "1":
rename= "000" + rename
break;
case "2":
rename= "00" + rename
break;
case "3":
rename= "0" + rename
break;
case "4":
break;
}
rename = baseName +rename +extension
file.rename(rename);
}
for(var i = 0; i < files.length; i++){
file= files[i];
rename2= files[i].name.toString();
file.rename( "©\_" + rename2);
}
}
}
catch(e){
alert(e + ' ' + e.line);
}
}