Site icon SumTips

PowerShell: Automatically Cycle Through Tabs in Any Browser

There are extensions available that automatically rotates through open browser tabs. This could be convenient, say, if you wish to monitor various reports, news, sport scores, or stock updates that are open in multiple browser tabs. You can easily navigate through those tabs and view information without manual interaction.

Automatically Cycle Through Tabs in Any Browser

The problem with dedicated extensions is they are browser dependent. If you are looking for a universal solution that works with all browsers, here’s a useful PowerShell snippet.

while(1 -eq 1){
	$wshell=New-Object -ComObject wscript.shell;
	$wshell.AppActivate('Opera'); # Activate on Opera browser
	Sleep 5; # Interval (in seconds) between switch 
	$wshell.SendKeys('^{PGUP}'); # Ctrl + Page Up keyboard shortcut to switch tab
	$wshell.SendKeys('{F5}'); # F5 to refresh active page
}

When you run this script, PowerShell would switch focus to Opera browser and cycle through all open tabs with five second intervals. It would also reload the content of the active page each time.

Here, we have “Opera” in the code. You can as easily automatically cycle through tabs in Google Chrome, Mozilla Firefox, Microsoft Edge, or Internet Explorer. All you need to do is change $wshell.AppActivate('Opera'); with the browser you are using.

In the same way, you can alter the interval from 5 seconds to another one, for instance 30 seconds, based on the requirement by editing Sleep 5; value. Additionally, you have the option to disable the automatic reloading of pages when tabs get activated by simply commenting or removing the line $wshell.SendKeys('{F5}');.

By default, PowerShell switches to the last open browser window on executing the script. This can be changed to the window of interest by manually opening it.

The script is designed with multiple tabs in mind, but it can as well be used on a website that does not reload its content regularly. You can remove or comment out $wshell.SendKeys('^{PGUP}'); to auto reload pages after a specific time interval.

That’s all.

Exit mobile version