Script Help - Check if Tab Exists in Pane

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
VeeGee

Script Help - Check if Tab Exists in Pane

Post by VeeGee »

Good evening all,
I am slowly working on a script and hit a snag. I'd like to have an if/then/else section that would check if a tab w/the caption of Downloads exists in the top pane (P1) (in any location). When I have Downloads open, it will always be in the top pane, so I can limit my search to P1.

I started w/this (below), but I think it just checks the caption of the selected tab when the script was run. I'm not exactly sure at this point how to loop through open tabs in a specific pane.

Code: Select all

 /*if (tab("get", "caption") != "Downloads") {
  ......
 } else {
  ......
 };*/

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

Re: Script Help - Check if Tab Exists in Pane

Post by highend »

Code: Select all

    $tabExists = False;
    if (get("pane") == 1) {
        while ($i++ < tab("get", "count")) {
            if (tab("get", "caption", $i) LikeI "Downloads") {
                $tabExists = True;
                break;
            }
        }
    }
    if ($tabExists == True) {
        // Do something...
    } else {
        // Do something else...
    }
One of my scripts helped you out? Please donate via Paypal

VeeGee

Re: Script Help - Check if Tab Exists in Pane

Post by VeeGee »

Thank you very much for your reply. I was able to add your snippet and modify. Your example worked perfectly when I was in P1. To adjust it to work no matter what pane I start with, I made some changes. I'm not thinking this is the most elegant way to do it, but it is working. Any further tweaks are greatly appreciated.

Code: Select all

 $tabExists = False;
 foreach($token, "P1,P2", ",") {
	focus $token;
	while ($i++ < tab("get", "count")) {
		if (tab("get", "caption", $i) LikeI "Downloads") {
			$tabExists = True;
			break;
		}
	}
 }
 if ($tabExists == True) {
  // do something
 } else {
  // do something else
 }
 

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

Re: Script Help - Check if Tab Exists in Pane

Post by highend »

You've asked for a way to determine if a tab with a specific caption exists in P1, so...

Regarding your script: No, you need to break out of both loops, otherwise it will check
P2 for that caption as well...

And maybe you should return to the current active pane if no caption was found...

Code: Select all

    $tabExists  = False;
    $activePane = "P" . get("pane");
    foreach($pane, "P1|P2") {
        focus $pane;
        while ($i++ < tab("get", "count")) {
            if (tab("get", "caption", $i) LikeI "Downloads") {
                $tabExists = True;
                break 2;
            }
        }
    }
    if ($tabExists == True) {
        // Do something...
    } else {
        if ($pane != $activePane) { focus $activePane; }
        // Do something else...
    }
One of my scripts helped you out? Please donate via Paypal

VeeGee

Re: Script Help - Check if Tab Exists in Pane

Post by VeeGee »

Pretty damn slick, thank you for the help. FYI - incoming tip donation (for this and previous times you've helped me).

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

Re: Script Help - Check if Tab Exists in Pane

Post by highend »

FYI - incoming tip donation (for this and previous times you've helped me)
Thanks :tup:
One of my scripts helped you out? Please donate via Paypal

Post Reply