Getting Selected File Count (jscript)

What am I doing wrong here? It either always returns 1 (whether I select a single file, or several files), or "undefined".

I've tried this (always returns 1):


function OnClick(data) {

	var tab = data.func.sourcetab;
	var count = tab.selstats.selfiles;

	DOpus.Output (count);

and this (returns Undefined):


function OnClick(data) {

    var count = new Enumerator(data.func.sourcetab.selstats);

    DOpus.Output (count);

I'm more adept at VBScript, and can do it no problemo there, but not as much so with jscript, and I'm having to use it in this case. :stuck_out_tongue:

The first script works here, when run from a lister toolbar with multiple files selected.

Do you have multiple (dual) listers opened? I have a scripted global hotkey that does not work with multiple listers open.
Whenever DO does not have focus the global hotkey fails, the sourcetabs id is "0" in these cases.
I don't know if that is intentional or not, but maybe that's the same thing you deal with?

Leo, Jon can you tell if a null-tab is expected to ever get through to data.func.sourcetab?

It's expected if there is no source tab, at least. Global hotkeys should probably enumerate the listers/tabs or set an explicit source folder to find the source that makes sense for them.

Thanks guys. :slight_smile:

It turns out that I was just doing a compare after those 2 examples wrong, in the full script (I only ripped out the example code above, from the full code). doh! lol

If you want to, my topic can be deleted, as it was all my fault. :stuck_out_tongue:

Thanks as well.. I tested once again and against the regular internal Select command.
For two dual listers, the Select won't do a thing in any lister, unless one of them has focus.
So this is basically the same for a global hotkey where the null-tab is being passed.

It's a bit confusing, in cases where you expect commands and scripts to pick up the last active source or any source at all automatically, it does not. And then there are situations where a particular command picks up items from a tab, though you did not tell it to do so.

If there is a specific schema behind that, I did not get it yet! o)

It's deterministic, but subject to change, and probably not something it makes sense to depend on in the first place.

What are you actually trying to do with the global hotkey?

Yes, maybe I also mixed in another issue I had. I remember creating a new Command object and running "Copy" or something, and although I did not set a sourcetab, it picked up items from somewhere I did not want it to.

The global hotkey is about selecting random items (in the last lister used) and then running the associated application.
Now that I know that a null-tab will be passed at times, going the "LastActive" lister route should solve that.
This one is easy to follow once you realize, that with multiple dual listers open, there are multiple source tabs and no default-source anymore. It's easier to understand than the other case, where a command or something picks up things unexpectedly.

Seems odd to do that from a global hotkey, when it depends on an active lister for context. If you're not in a lister when you push the key, how do you know/remember for sure which one it's going to pick random files from?

Maybe if you only tend to have one window open and don't want the extra step of switching back to it. Fair enough.

All that aside, the LastActive route makes sense if you want it to work that way, certainly.

Yes, currently the hotkey only works with a single lister opened. In this case the lister does not need to have focus. With two or more listers, the global hotkey only works with a specific lister having focus, but since I press that hotkey with some kind of media player in the front, DO never has focus.

Weird usecase? Think of random playback of music, videos or images from the last folder you visited before switching to your favorite viewer, player or media center, then it's not that weird anymore, or is it? o)

Still seems weird to me.

I'd trigger the music player from the folder.

Rather than switch from the folder to the music player, and then trigger the folder again to do something to the music player.

But to each their own!

This hotkey selects random items, so there's no need to switch back to the folder to choose something once the playing application is launched (fullscreen). There's also a projector involved and a bunch of crazy people, so mhh, maybe you're right and it is weird. o)