Event: CloseTabSiblings (autoclose equal tabs in tab-row)

CloseTabSiblings - an event based script to automatically close equal tabs already open, when opening new tabs or changing folders.
There's also a command "CloseTabSiblings" included, you can unregister the event and make use of the command only if you wish.

Description:
I made this because I often end up with multiple tabs showing the same folder.
Additionally I think I'm too lazy to look if a specific tab is already opened for the folder/tab I'm going to open next. o)

Usage:
If the event is active (default is enabled - watch the script config), there's nothing more to do than making sure the script is enabled.
Whenever you open a new tab/folder, any pre-existing tab with the same folder opened on the same tab row, will be closed automatically.

If the event is not enabled, you can add the command "CloseTabSiblings" to the folder filetype events and run it after any "GO NEWTAB" command e.g.
You can also put the command on a dedicated button to close all tabs which have the same folder opened as the current tab.

Finetuning / Config:
You can add a blacklist of paths to never close, en/disable qualifiers or statically protect the first n-number of tabs in a row.
If qualifiers are enabled (default), pressing when opening or changing tabs or folders temporarily disables tab closing.
Pressing protects the tab itself and stops closing any tabs which show the same new path.

Installation:
To install the event/command, download the *.js.txt file below and drag it to Preferences / Toolbars / Scripts.
After that the event/command shall be ready to use, just make sure the script is enabled (should be by default).

Download:

2 Likes

excellent idea, very handy, but...
Event.Folder: CloseTabSiblings: Error at line 73, position 2
Event.Folder: CloseTabSiblings: Object doesn't support this property or method (0x800a01b6)
any ideas?

tbone is very cutting edge and always uses the latest features :slight_smile:

If you update to the latest beta it should work fine.

perfect thanks very much!!

Updated to v0.2
To come around the non-existing "locked" property of tabs, I added some options to make life easier:

  • lock tabs by blacklist of paths
  • lock tabs by position
  • lock tabs by using qualifiers

Updated to v0.2.2

Thank you for this very nice script!
I've noticed a bugs: when I restart lister, it would close ALL tabs but currently active one (including non-duplicate tabs) in case it finds any duplicates instead of closing just the duplicates

Also, would it be possible to add the following two modifications.

  • Add a command that would ignore all "temporarily protected" tabs? E.g. when I open a new tab with a modifier (Ctrl+T most of the time) the path gets "protected" and even if I click my toolbar button with CloseTabSiblings command these duplicate tabs don't get closed

  • Separate tab change and folder change events so I can only close duplicates whenever a tab is opened/closed. However, this might still not achieve what I'd like, see below

What I basically need is
a) an ability to open a new tab with Ctrl+T without it being closed right away as a duplicate
b) NOT having this new tab/path protected in case I open another tab (or close another tab for that matter)
c) have command trigger on any tab changes (new/close), but on folder changes (i.e. during navigation). If I happen to temporary navigate to the same path as is open in another tab, I don't want anything to close.

It seems to me the current option set doesn't allow this, but maybe I just don't know how to configure it properly.

  1. So you'd like some kind of "FORCE" option, I think that can be done.

a) You can set DO to always open empty tabs (I find that the fastest and most convenient way, maybe you like it as well).
It can be done in the preferences. And regarding the CTRL+T shortcut: Change the command to "Go NEWTAB" (remove CURRENT argument). With tabs always opening empty, no tab will get closed right away.
You can also add the "NOSCRIPT" argument to your shortcut (leave the CURRENT in there if you like), it prevents DO from triggering any script events, so no tabs will close.

b) Sorry, I don't understand. Is this related to point a) as well?

c) Seems reasonable.

I got an idea — I think it should be "Force except for current path". This way I can just bind it to a new tab open and the only duplicate tabs left after this operation would be the last two.

Unfortunately, that's rather inconvenient as I'd lose my current path — and the main reason I'd open a new tab instead of my favorite folder (either via Winkey+# shortcuts or by just alt-clicking on the favorite list in the tree view) is precisely because I need to navigate around current path, i.e. when a few "go up/select another folder" commands are faster than starting from a favorite folder position.

Thank you for the tip, at the moment it seems even worse than having Ctrl protect the path as it means none of the other duplicate tabs will close. But maybe if I disable qualifiers and add your command to run after closing a tab, that could be a temporary solution

Yes, it's an additional condition to a) that would make the script behave like I would ideally like it to behave.
Let me clarify this point. If I Ctrl-T a new tab, this path will get "protected" (assuming qualifiers are on), which is nice as it prevents this new duplicate tab TabADup from being closed automatically.
Now suppose I just leave these two duplicate tabs TabA and TabADup hanging there and switch to a different 3rd tab and then invoke CloseTabSiblings. I would like the "path protection" to fade by then, so that any subsequent use of the script would close TabADup. However, this doesn't happen because the path stays protected until the script is restarted, thus polluting my tab space.
Moreover, if I happen to navigate to this path in the 3rd tab, then it wouldn't close duplicates either since this path is protected.

c) there is also a typo, I meant "but NOT on folder changes"

Hm, I just now realized that your script closes tabs duplicating current path only, not all duplicates :frowning:
That's quite a downer and is even worse than lack of the other features I mentioned earlier. Is there a chance to please extend duplicate check to all tabs, not just current tab? Then I'd be able to get to 90% perfection with Autohotkey (for closing duplicates on opening a new favorite folder with a shortcut) and adding CloseTabSiblings to close tab (ctrl-W) shortcut — all in with qualifiers off (to avoid protecting any paths) and folder/tab change scan off (to avoid auto-closing new tabs "Go CURRENT NEWTAB").

I have following suggestion: If tabs are in a linked state, make them an exception, so that double tabs stay untouched. I have following usecase in mind.

K:\Pictures <=> N:\Pictures is linked, but i also want to use K:\ Pictures <=> L:\Secondlocation, which means, that one lister side would require an exception double location.

Thanks Abr, will see what I can do for the next upload.
I fixed some other parts on it already, since CloseTabSiblings was doing some things DO did not like the way it did them.
DO would eat all memory available and bring my machine to full stop, whenever a tab auto-closed, wonder why nobody else noticed. But now you know, if you change folders and your system eventually stops working because of high memory usage, it is this script addin! Well, it might be. o)

Thanks tbone. I had no issues, regarding the memory, so far. So maybe other co-factors might be involved. Looking forward to the new version, but no hurry, of course.

Sounds super but I'm confused about how this works.

Am I supposed to be able to have two TEST tabs open?

Didn't touch the settings.

Yes, in specific cases this is expected. CloseTabSibling is primarily checking whenever you open tabs or navigate folders if there are existing Tabs to close. I think about expanding this to also match other peoples expectations. o)

I think I must be misunderstanding something fundamental. When I had the TEST tab open, then navigated to TEST in another tab, I thought that was exactly the use case described at the top, and expected the first tab to close. What am I misunderstanding?

Could be the tab start index kicking in. You can set a start index to always protect the first x tabs from closing.

Hey tbone, thank you for your troubleshooting thoughts. Never heard of a tab start index, sounds cool but I don't think I have one. I can close all the tabs except one. Tried disabling all other scripts in case of a conflict, still no luck. Don't worry about it, I just wanted to have a play with it. :slight_smile: Have a great weekend.

I think tbone meant the script has one you can adjust :slight_smile:

@tbone Hey man, sorry, just looked at the script code for fun, and realized that the start index is a tbone thing, not a DO thing. You were right, I set it to zero in the config and now it seems to work! Thank you!!! :thumbsup:

EDIT just saw wires got crossed and Jon posted the same info.