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

Participating Frequently
November 30, 2008
Thanks

Good Luck.
______
My Si tes
Known Participant
September 15, 2005
Yeah, I concluded that it is a scoping issue, but only triggers a problem when you call a function that causes other scripts to run. In your case, alert goes back to the windows message pump and conceivably causes other scripts to run. In my case, event handlers were firing when I selected thumbs.

In any case, it's good coding practice to use "var" and make sure they are scoped locally and avoid the issue all together.

--John
Known Participant
September 15, 2005
I also came across this today. I tested it with a loop:

for (i = 0; i<3;i++) {alert(i)}

It did the first iteration then stopped. This suggests to me it is a scoping issue independent of any particular function in use though it was preceded by a getSelectedFiles type function.

There is a possibly related bug in Photoshop JS that makes 'i' inside a for loop unchangeable if you specified the 'for' with i++, but variable if specified with i = i+1 (in the first case i = 3 within the loop has no effect on the loop, in the second case it sets the loop control i to 3).

lol you know you've been doing too much scripting when you keep ending sentences with ; instead of .

Andrew
Known Participant
August 5, 2005
Thanks.

You might recommend that this get documented in the Adobe Bridge JavaScript Reference (I couldn't find it in there). I think the place it belongs is right next to the recommended JavaScript books. When trying to find plain JavaScript reference information on the web, this would have helped me a lot to know what version I was looking for.

--John
Known Participant
August 5, 2005
ECMA-262 Edition 3, or JavaScript 1.5

Bob
Adobe WAS Scripting
Known Participant
August 5, 2005
I did Google it and find plenty of real namespace proposals from Netscape/Mozilla, but they are from 2002 and refer to JavaScript 2.0 and ECMAScript 4.0 so I can't tell if those proposals died and never became real or if they are just taking forever to get done and are still coming or if they are already implemented.

BTW, what version of ECMAScript is ExtendScript modelled after? The Bridge Scripting reference doesn't seem to say.

--John
Known Participant
August 5, 2005
Hmmm. That's not very convenient and it doesn't prevent my mistake. At the cost of a lot more typing, it can prevent other scripts from accidentally referencing or colliding with your variable names, but it doesn't prevent you from accidentally colliding with other people's variables if you leave off the object qualifier when you are typing.

When I saw a reference to namespaces in something I was reading, It thought it was more like real namespaces (e.g. C++ namespaces) where you define a scope where all declared or referenced variables are automatically in that namespace unless they are explicitly referenced/declared otherwise. Does JavaScript not have that capability?

It would be more like this:

namespace MyProgram {

var i = 3;

// lots of other code here

};

With a real namespace, "i" wouldn't be a global variable. It's real name/declaration would be MyProgram.i or MyProgram::i depending upon the syntax.

Does JavaScript not have real namespaces?

I get that I can explicitly declare everything to a scope of MyProgram to simulate some benefits of namespaces, but that's a lot of extra typing and, presumably a bunch of extra work for the interpreter since there's at least one extra dictionary lookup for every variable or function reference.

--John
Known Participant
August 5, 2005
jfriend00@adobeforums.com wrote:

> Does JavaScript not have real namespaces?

The current rev does not. The next major ECMAScript rev has lots of new stuff
but I don't recall if namespaces are one of them. Try google and check the
mozilla.org site in particular.

>
> --John
Known Participant
August 5, 2005
It's nothing special:

var myNamespace = {}; // the namespace is just an "object" to which
// you attach everything in your script.

MyNameSpace.myGlobalVariable = 12;
MyNameSpace.menu = MenuElement.create(...);
MyNameSpace.execute = function( menu ) {
// some really fancy stuff here
}
MyNameSpace.menu.onSelect = MyNameSpace.execute;

et cetera

Bob
Adobe WAS Scripting
Known Participant
August 5, 2005
That's what I guessed was happening. Thanks.

I'll have to look into JavaScript namespaces. If they are anything like namespaces in C++ or python, it seems like I could set up a namespace in my script file and that would keep me from ever colliding with someone else's global variables (since that's what they are for).

--John
Known Participant
August 5, 2005
Actually, the problem is more than likely in code that is executing as a result of app.document.select(). When a thumbnail is selected, an event is fired. That event firing causes an interation through event handlers (i?). Also if you have StockPhoto installed, they do background checking to see if one of the SP files is selected. Probably an i or 2 in there as well.

Bob
Adobe WAS Scripting