Close Tab By Name ?

Discuss and share scripts and script files...
GreetingsFromPoland
Posts: 224
Joined: 29 Sep 2022 14:20
Location: Win10 @125%

Close Tab By Name ?

Post 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"); ?

RalphM
Posts: 1935
Joined: 27 Jan 2005 23:38
Location: Cairns, Australia

Re: Close Tab By Name ?

Post 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.
Ralph :)
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)

GreetingsFromPoland
Posts: 224
Joined: 29 Sep 2022 14:20
Location: Win10 @125%

Re: Close Tab By Name ?

Post 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 ?

klownboy
Posts: 4142
Joined: 28 Feb 2012 19:27

Re: Close Tab By Name ?

Post 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. :)
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

admin
Site Admin
Posts: 60619
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Close Tab By Name ?

Post by admin »

Yes, makes sense. :tup:

klownboy
Posts: 4142
Joined: 28 Feb 2012 19:27

Re: Close Tab By Name ?

Post 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.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

highend
Posts: 13333
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Close Tab By Name ?

Post by highend »

+1
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4142
Joined: 28 Feb 2012 19:27

Re: Close Tab By Name ?

Post 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.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

GreetingsFromPoland
Posts: 224
Joined: 29 Sep 2022 14:20
Location: Win10 @125%

Re: Close Tab By Name ?

Post 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 :

Code: Select all

tab("close", , "Search Results");
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.

admin
Site Admin
Posts: 60619
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Close Tab By Name ?

Post 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.

admin
Site Admin
Posts: 60619
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Close Tab By Name ?

Post by admin »

GreetingsFromPoland wrote: 27 Oct 2023 18:57 is there any way to suppress the message ?
I'll add a flag.

klownboy
Posts: 4142
Joined: 28 Feb 2012 19:27

Re: Close Tab By Name ?

Post 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.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

admin
Site Admin
Posts: 60619
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Close Tab By Name ?

Post 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.

klownboy
Posts: 4142
Joined: 28 Feb 2012 19:27

Re: Close Tab By Name ?

Post 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.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

admin
Site Admin
Posts: 60619
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Close Tab By Name ?

Post by admin »

It does.

Post Reply