Page 1 of 1

Close tabs to the right [Solved]

Posted: 21 Mar 2022 01:23
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?

Re: Close tabs to the right

Posted: 21 Mar 2022 06:40
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.

Re: Close tabs to the right

Posted: 21 Mar 2022 16:40
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 :-)