Skip to main content
Known Participant
August 5, 2005
Question

Why does Bridge hang when selecting thumbs

  • August 5, 2005
  • 13 replies
  • 1587 views
I've been working on a script that looks through all the currently visible images in Bridge and selects a subset of them. In my case, I'm selecting only the latest version of an image (e.g. the PSD, not the NEF). My code logic is working to identify the thumbs that I want to select, but when I try to actually select them in Bridge, I find that Bridge hangs.

The whole script is a bit complicated, but the relevant part to my problem is:

for (i = 0; i < fileNames.length; i++)
{
if (!fileNames.hasDerivative)
{
var thumbObj = currentThumbs[fileNames.thumbIndex];
app.document.select(thumbObj);
}
}

If I comment out the app.document.select line, the script works perfectly. I've even written debugging code that verifies that my script finds all the right thumbs. But, when I try to actually select them in Bridge, Bridge hangs and I have to kill it from task manager.

Is there something I'm either doing wrong or need to know about app.document.select(thumb) in Bridge? Why would that call hang? Could I somehow be passing an invalid thumb to this function? Is there a way I can write debugging code to test if it's a valid thumb I'm passing in all cases?

--John
This topic has been closed for replies.

13 replies

Known Participant
August 5, 2005
I get that using "var" is the correct way to use a locally scoped variable. That was just a coding goof on my part as I'm new to JavaScript and used to C++ where the compiler would catch declaration issues like this. For what it's worth, I had the same coding goof in three other "for" loops in the same function and they all worked fine.

What's weird is that there apparently is a globally scoped variable named "i" declared in some other piece of Bridge JavaScript because the code ran without error. And, even further weirdness, that globally scoped variable "i" gets it's value changed when I call app.document.select(). That's what was causing the infinite loop.

--John
Known Participant
August 5, 2005
John,

You must use the "var" statement in your loop. I can't tell you exactly why, but I ran afoul of this same issue a number of years ago doing some GoLive scripting.

I did find this in a JS reference:

Variable Scope

When you set a variable identifier by assignment outside of a function, it is called a global variable, because it is available everywhere in the current document. When you declare a variable within a function, it is called a local variable, because it is available only within the function.

Using var to declare a global variable is optional. However, you must use var to declare a variable inside a function.

Bob
Adobe WAS Scripting
Known Participant
August 5, 2005
I figured out that if I changed:

for (i = 0; i < fileNames.length; i++)

to

for (var i = 0; i < fileNames.length; i++)

that it starts working. I presume the "var" that I added is scoping this use of the variable i to a local scope and that's what makes it start to work, so it must have been conflicting with some more global use of that variable name.

A wild guess is that calling "app.document.select()" triggers some OnSelect methods and maybe there's a conflicting use of a globally scoped variable named i in some of those that causes my for loop to never complete. Anyway, it's working now.

Since I'd rather understand exactly why it didn't work before, I'd appreciate any other thoughts on why it hung with the "var" declaration.

--John