Page 1 of 2
Close Tab By Name ?
Posted: 26 Oct 2023 14:02
by GreetingsFromPoland
hi! i have a script that resets my panes to their default locations, active ones, etc. it works really well. recently i got into the habit of closing my
Search Results tabs after i am done with a search. i wanted to do this automatically as part of my reset script.
i made/modified a function (that works) based on some code that i found here that highend (i believe) posted in another thread. when reviewing the help file i see that you can close a tab by index; however, i didn't see a way to close it by caption name. it's probably possible to nest some commands into a one-liner, but i was not successful.
here is the function i am using (which is called in the script when processing each pane separately) :
Code: Select all
function closeSearchResults() {
$i = tab("get", "count")+1;
while ($i-- > 0) {
$tabCaption = tab("get", "caption", $i);
if ($tabCaption LikeI "Search Results*") {
tab("close", 0, $i);
}
}
}
is there a shorter way to close by name ? something like
tab("close", "Search Results"); ?
Re: Close Tab By Name ?
Posted: 26 Oct 2023 15:35
by RalphM
Have you ever looked into tabsets?
If not, this is the way to go when you want to reset whole panes to a predefined state.
I have several tabsets for different tasks and I just load them into either pane whenever needed.
If I want to change one of the preset tabsets I just make sure to save it before loading another one.
Re: Close Tab By Name ?
Posted: 27 Oct 2023 13:46
by GreetingsFromPoland
hi! thank you for the reminder. i have used them in the past and apparently i had some saved.
for some time now i have locked down my tab layout and workflow. dual pane, each with an unlocked Default Tab set on the left. each pane then has it's own locked tabs that i use. this way, any browsing that i do, always uses the Default Tab of the selected pane. i rarely go outside of my locked panes, so this setup works.
maybe what i should do is update my tab sets to this new layout and script from there (to load the appropriate one in the correct pane). thanks again for the reminder.
any tips on my question about "closing tab by name" command or syntax ? maybe scripting could get an update here ?
Re: Close Tab By Name ?
Posted: 27 Oct 2023 14:21
by klownboy
GreetingsFromPoland wrote: ↑27 Oct 2023 13:46
any tips on my question about "closing tab by name" command or syntax ? maybe scripting could get an update here ?
Closing a tab via the tab scripting command currently requires the tab's index
tab([operation], [data], [index], [ID]) That's why scripts out there cycle through all the tabs using
while or
foreach.
It would be nice though. Make a wish.

Re: Close Tab By Name ?
Posted: 27 Oct 2023 15:29
by admin
Yes, makes sense.

Re: Close Tab By Name ?
Posted: 27 Oct 2023 16:32
by klownboy
That will come in handy. I think what we really want is the "caption" (what is displayed) as opposed to the full tab name.
Re: Close Tab By Name ?
Posted: 27 Oct 2023 16:42
by highend
+1
Re: Close Tab By Name ?
Posted: 27 Oct 2023 18:43
by klownboy
Hey Don, when I'm currently located on a tab (e.g., index 12) and I enter something like echo tab("get", "index", "travel");, instead of getting the index for my "Travel" tab (e.g., index 14), I get the index of the current tab.
Re: Close Tab By Name ?
Posted: 27 Oct 2023 18:57
by GreetingsFromPoland
hi! thank you very much for adding this.
If there is no match, an error message "Tab name not found" is displayed and no operation is performed.
is there any way to suppress the message ? i tried these and the message was still displayed when a tab matching the name didn't exist :
and
Code: Select all
tab("close", 0, "Search Results");
just checking if i did something wrong. was trying to "close tab, be silent if you don't exist" since i have this script assigned to a CTB.
Re: Close Tab By Name ?
Posted: 28 Oct 2023 10:54
by admin
klownboy wrote: ↑27 Oct 2023 18:43
Hey Don, when I'm currently located on a tab (e.g., index 12) and I enter something like
echo tab("get", "index", "travel");, instead of getting the index for my "Travel" tab (e.g., index 14), I get the index of the current tab.
Sure? Cannot reproduce.
Re: Close Tab By Name ?
Posted: 28 Oct 2023 11:05
by admin
Re: Close Tab By Name ?
Posted: 28 Oct 2023 12:14
by klownboy
admin wrote: ↑28 Oct 2023 10:54
klownboy wrote: ↑27 Oct 2023 18:43
Hey Don, when I'm currently located on a tab (e.g., index 12) and I enter something like
echo tab("get", "index", "travel");, instead of getting the index for my "Travel" tab (e.g., index 14), I get the index of the current tab.
Sure? Cannot reproduce.
I'm all wet. It works fine. Silly question though, if I use a wildcard like * in a situation where it is not needed like I had,
echo tab("get", "index", "Travel*"); when the caption is simply "Travel", should it still work or with the asterisk, there
must be something else there on the right side of travel (i.e., the asterisk can't signify nothing)?
Edit: I can't get this to work echo tab("get", "index", "Roaming*"); for my "default" tab which has a "rename" block of
Roaming <drive>:\<folder>|D:\Graphics\Icons\Combined\BREEZE.ICO||Roaming <drive>:\<folder>
I receive a tab name not found message.
Re: Close Tab By Name ?
Posted: 28 Oct 2023 13:38
by admin
Next beta has this fix, maybe this caused it?
Code: Select all
! SC tab: Passing "index" with wildcards used case-sensitive matching. Fixed.
Re: Close Tab By Name ?
Posted: 28 Oct 2023 14:33
by klownboy
Thanks Don. How about the other part of my issue with the wildcard? Should echo tab("get", "index", "Travel*"); work if the name is only Travel? I know that's probably a general question on the use of wildcard * (i.e., should it work if nothing is on the right side of travel)?
Edit: I Googled it, and it appears it should.
Re: Close Tab By Name ?
Posted: 28 Oct 2023 15:42
by admin
It does.