1K Messages
•
17.1K Points
Wed, May 16, 2018 8:41 PM
Bridge: document.refresh not working in script
I have a Bridge script to automate renaming files. I photograph products tethered with four variants, all using the same base filename with a variant letter. Filenames are always all caps (company naming style.)
Example: ABC111-A, ABC111-B, ABC111-PA
This meant typing in the same base name four times with the variant letter (I always name the first file when initially captured.) So I wrote a script to speed this up and it works great. Except. I might have stumbled across a display bug.
I'm trying to avoid switching back and forth with caps lock (leave it off) so I can also answer emails. Originally I took the input, converted to uppercase, and changed the filename. But that left the first file lowercase unless I remembered to switch.
So, fine, I'll just convert renamed files to uppercase. But I can't get the Bridge browser window to refresh. Synchronous mode doesn't help. If I manually refresh with F5, the extra files go away. I've tried moving the document.refresh statement inside the Try block, with and without synchronous mode, document.refresh before exiting synchronous mode, etc. No luck.
See screen captures. I have not tested this on the Mac yet.



Script follows:
#target bridge
if(BridgeTalk.appName == 'bridge'){
FT = MenuElement.create('command', 'Rename', 'at the end of Tools');
FC = MenuElement.create('command', 'Rename', 'after Thumbnail/Open', this.menuID);
}
FT.function(){
Renamer();
}
FC.function(){
Renamer();
}
function Renamer(){
var thumbs = app.document.selections;
var newName = '';
var Title = [];
var counter = 0;
var variant = ['-PA', '-PB'];
if(thumbs.length != 4) return;
app.synchronousMode = true;
try{
newName = prompt('Enter part number');
for (var a in thumbs){
var selectedFile = thumbs[a].spec;
Title[a] = selectedFile.name;
Title[a] = (Title[a].split( '.' ))[0];
if(Title[a].substr(0, 4) == 'IMG5'){
thumbs[a].name = newName + '-B.CR2';
}
if(Title[a].substr(0,4) == 'IMG_'){
thumbs[a].name = newName + variant[counter] + '.CR2';
counter = counter + 1;
}
thumbs[a].name = thumbs[a].name.toUpperCase();
}
}
catch(e){
}
app.synchronousMode = false;
app.document.refresh();
}
Example: ABC111-A, ABC111-B, ABC111-PA
This meant typing in the same base name four times with the variant letter (I always name the first file when initially captured.) So I wrote a script to speed this up and it works great. Except. I might have stumbled across a display bug.
I'm trying to avoid switching back and forth with caps lock (leave it off) so I can also answer emails. Originally I took the input, converted to uppercase, and changed the filename. But that left the first file lowercase unless I remembered to switch.
So, fine, I'll just convert renamed files to uppercase. But I can't get the Bridge browser window to refresh. Synchronous mode doesn't help. If I manually refresh with F5, the extra files go away. I've tried moving the document.refresh statement inside the Try block, with and without synchronous mode, document.refresh before exiting synchronous mode, etc. No luck.
See screen captures. I have not tested this on the Mac yet.
Script follows:
#target bridge
if(BridgeTalk.appName == 'bridge'){
FT = MenuElement.create('command', 'Rename', 'at the end of Tools');
FC = MenuElement.create('command', 'Rename', 'after Thumbnail/Open', this.menuID);
}
FT.function(){
Renamer();
}
FC.function(){
Renamer();
}
function Renamer(){
var thumbs = app.document.selections;
var newName = '';
var Title = [];
var counter = 0;
var variant = ['-PA', '-PB'];
if(thumbs.length != 4) return;
app.synchronousMode = true;
try{
newName = prompt('Enter part number');
for (var a in thumbs){
var selectedFile = thumbs[a].spec;
Title[a] = selectedFile.name;
Title[a] = (Title[a].split( '.' ))[0];
if(Title[a].substr(0, 4) == 'IMG5'){
thumbs[a].name = newName + '-B.CR2';
}
if(Title[a].substr(0,4) == 'IMG_'){
thumbs[a].name = newName + variant[counter] + '.CR2';
counter = counter + 1;
}
thumbs[a].name = thumbs[a].name.toUpperCase();
}
}
catch(e){
}
app.synchronousMode = false;
app.document.refresh();
}
Problems
•
Updated
3 years ago
7
6
Helpful Widget
How can we improve?
Tags
No tags available
Responses
lumigraphics
1K Messages
•
17.1K Points
3 years ago
0
0
lumigraphics
1K Messages
•
17.1K Points
3 years ago
#target bridge
if(BridgeTalk.appName == 'bridge'){
FT2 = MenuElement.create('command', 'Rename2', 'at the end of Tools');
FC2 = MenuElement.create('command', 'Rename2', 'after Thumbnail/Open', this.menuID);
}
FT2.function(){
Renamer2();
}
FC2.function(){
Renamer2();
}
function Renamer2(){
app.synchronousMode = true;
var thumbs = app.document.selections;
var newName = '';
var counter = 0;
try{
newName = prompt('Enter part number');
for (var a in thumbs){
thumbs[a].name = newName + counter + '.CR2';
counter = counter + 1;
thumbs[a].name = thumbs[a].name.toUpperCase();
}
}
catch(e){
}
app.document.refresh();
app.synchronousMode = false;
}
0
0
paul_riggott
361 Messages
•
6.9K Points
3 years ago
2
0
paul_riggott
361 Messages
•
6.9K Points
3 years ago
Docs say:-
name String The label displayed for the thumbnail. Read/write.
Default is the path value.
Nothing about file renaming, that's why I suggested using rename David.
0
0
lumigraphics
1K Messages
•
17.1K Points
3 years ago
0
0
avinash_kumar_singh_ezvq1txxiddi0
30 Messages
•
460 Points
3 years ago
Instead of app.document.refresh(); try
app.document.chooseMenuItem("Refresh");
Here is the final script and it worked for me on Win 10 also the file count is getting correct
Thanks
Avinash
Code :
#target bridge-8
if(BridgeTalk.appName == 'bridge'){
FT = MenuElement.create('command', 'Rename', 'at the end of Tools');
FC = MenuElement.create('command', 'Rename', 'after Thumbnail/Open', this.menuID);
}
FT.function(){
Renamer();
}
FC.function(){
Renamer();
}
function Renamer(){
var thumbs = app.document.selections;
var newName = '';
var Title = [];
var counter = 0;
var variant = ['-PA', '-PB'];
if(thumbs.length != 4) {
return;
}
app.synchronousMode = true;
try{
newName = prompt('Enter part number');
for (var a in thumbs){
var selectedFile = thumbs[a].spec;
Title[a] = selectedFile.name;
Title[a] = (Title[a].split( '.' ))[0];
if(Title[a].substr(0, 4) == 'IMG5'){
thumbs[a].name = newName + '-B.CR2';
}
if(Title[a].substr(0,4) == 'IMG_'){
thumbs[a].name = newName + variant[counter] + '.CR2';
counter = counter + 1;
}
thumbs[a].name = thumbs[a].name.toUpperCase();
}
}
catch(e){
}
app.synchronousMode = false;
app.document.chooseMenuItem("Refresh");
}
2
0