Close tabs to the right [Solved]

Discuss and share scripts and script files...
Post Reply
John_C
Posts: 336
Joined: 16 May 2018 20:04

Close tabs to the right [Solved]

Post by John_C »

Code: Select all

"Close Tabs to the Right"
  $indexOfCurrentTab = tab("get", "index");
  $numberOfTabs = tab("get", "count");
  $numberOfTabsToBeClosed = $numberOfTabs - $indexOfCurrentTab;
  while ($i++ < $numberOfTabsToBeClosed) {
    if (tab("get", "flags", $i) == 0) { // Don't close locked or iconized tabs
      tab("close", 0, $indexOfCurrentTab + 1);
    }
  }
This is a script to close all the tabs to the right of the current tab.

I try to make it to avoid closing locked or iconized tabs, but there is some error: it closes some other tabs instead. Could anybody help?
Last edited by John_C on 21 Mar 2022 16:42, edited 1 time in total.

jupe
Posts: 3290
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Close tabs to the right

Post by jupe »

Because you are going to be selectively closing tabs on the right, its probz better to start at the end and work backwards else your index will change after each tab closure, here is one way to do it,

Code: Select all

  $i   = tab("get", "count") +1;
  $tab = tab("get", "index");
  while ($i-- != $tab +1) {
    if !(tab("get", "flags", $i)) { // Don't close locked or iconized tabs
      tab("close", 0, $i);
    }
  }
I haven't really tested it, so you might need to make mods.

John_C
Posts: 336
Joined: 16 May 2018 20:04

Re: Close tabs to the right

Post by John_C »

Thanks, this works without any problems.

I have created another script to close "all other" tabs. It seems to work fine:

Code: Select all

"Close All Other Tabs"
  $indexOfCurrentTab = tab("get", "index");
  $i = tab("get", "count") +1;
  while ($i-- != 1) {
    // Don't close locked or iconized tabs
    if !(tab("get", "flags", $i) || $i == $indexOfCurrentTab) {
      tab("close", 0, $i);
    }
  }
If you see something is wrong, let me know :-)

Post Reply