Page 1 of 2
Close tabs to the right
Posted: 06 Sep 2018 03:12
by John_C
Here is my script to implement "close tabs to the right" ability, which could be seen in web browsers and tabbed text editors / IDEs.
Any suggestions about how it could be improved are welcome.
Code: Select all
"Close Tabs to the Right"
$indexOfCurrentTab = tab("get", "index");
$numberOfTabs = tab("get", "count");
if ($indexOfCurrentTab != $numberOfTabs) { // If we aren't on rightmost tab already
$numberOfTabs = $numberOfTabs - $indexOfCurrentTab;
while ($i < $numberOfTabs) {
$i++;
seltab +; // Select next tab
tab("close", 0);
}
}
Re: Close tabs to the right
Posted: 06 Sep 2018 07:35
by highend
Why are tabs selected before they get closed?
Code: Select all
$curTabID = tab("get");
$cntTabs = tab("get", "count");
$maxTabs = $cntTabs - $curTabID;
while($i++ < $maxTabs) { tab("close", 0, $curTabID + 1); }
Yeah, this will fire if someone is already on the rightmost tab but there is no tab to close -> No harm will be done.
If you don't want this, init $i to 0 before doing the loop...
Re: Close tabs to the right
Posted: 06 Sep 2018 12:26
by John_C
@highend Wow, cool, thanks!

But I don't understand something. In your code you have variable "curTabID", but from what I see, it actually store an index, instead of ID.

Re: Close tabs to the right - my implementation
Posted: 06 Sep 2018 12:33
by highend
Then rename that variable to $thisistheindexofthecurrenttab...
Re: Close tabs to the right - my implementation
Posted: 06 Sep 2018 12:40
by John_C
highend wrote:Then rename that variable to $thisistheindexofthecurrenttab...
Yeah, I understand, thanks

I asked because I assumed you intended to use ID, instead of index
Re: Close tabs to the right
Posted: 07 Sep 2018 09:16
by highend
No, the code is about 5 years old, "ID" for tab() is just way younger (v18.40.0108 - 2017-09-29 16:43)
Re: Close tabs to the right
Posted: 08 Sep 2018 15:03
by klownboy
Hi highend, your script gave me an idea of how I could do something similar but to geared to suite my needs. Maybe some others would find value in it. Instead of closing all tabs to the right of the current tab, this modification will close all tabs to the right of your normal setup's right most tab regardless of what tab is currently selected.
In my particular case my normal rightmost tab is my "default" tab which I name Roaming with the drive after it (e.g., Roaming <drive>:\<folder>|:browsenetwork). Obviously that name could be changed to suit whatever the user normally has. I know I could have used an index number or ID, but I wanted to be able to use the the same script on 3 different computers which have different rightmost tab IDs and indexes. The one thing is common however is the fact that they all have the right most tab set as the default and it's caption is Roaming folowed by the drive letter. I'll start using this bit of code in my script that works hand-in-hand with my USBDLM script - a script which recognizes external drive attachment/removal and opens and closes tabs associated with the drives.
Code: Select all
$i = tab("get", "count")+1; //add "1" since the first decrement in the while loop will subtract 1 from the total
while ($i-- > 0) { //worked backwards from the higher index tabs to reduce the reguired loops for this situation
$tabCaption = tab("get", "caption", $i);
if ($tabCaption LikeI "Roaming*") {end 1;} //change "Roaming*" to suit
else {tab("close", 0, $i); } //close tabs whether locked or not
}
Re: Close tabs to the right
Posted: 08 Sep 2018 16:47
by highend
Hi Ken,
yeah, people have different preferences. I for myself only ever use a single (locked) tab and load all additional tabs via a simplified tab manager script (which still saves the necessary tab states as well)
Re: Close tabs to the right
Posted: 08 Sep 2018 17:17
by klownboy
As you said, everyone has different preferences. For me, I just added that simple script to UMC - left click on Tab whitespace. It works great - getting my tabs clean again. The only problem arises when you have too many tabs and
no whitespace.

Re: Close tabs to the right
Posted: 09 Sep 2018 09:34
by highend

Maybe you should buy a few more monitors and extend XY to all of them?

Re: Close tabs to the right
Posted: 09 Sep 2018 14:47
by klownboy
highend wrote:
Maybe you should buy a few more monitors and extend XY to all of them?


No, I'm good with one monitor especially since it 27". I may either extend that little script to also work in the toolbar whitespace since I usually leave at least one empty space for a new CTB or I'l go to wide tabs.
Re: Close tabs to the right
Posted: 13 Dec 2018 17:57
by kotlmg
can you add the code to close tabs to the left?
Re: Close tabs to the right
Posted: 13 Dec 2018 19:30
by highend
That script already exists...
viewtopic.php?p=76917#p76917
A shorter version:
Code: Select all
$maxTabs = tab("get") - 1;
while($i++ < $maxTabs) { tab("close", 0, 1); }
Re: Close tabs to the right
Posted: 15 Dec 2018 16:01
by kotlmg
thanks a lot.
Re: Close tabs to the right
Posted: 02 Sep 2020 21:41
by mikeshick
my bad. I don't know the language too well, but what would i use to close the tabs to the right.
I tried the original script, but I get an error message:
https://www.dropbox.com/s/mf5a0raherr9b ... 4.png?dl=0