0

I am trying to make a script to alt tab every X seconds to a specified application window but so far I just managed to make one that alt tabs my 2 most recent tabs, can anybody help me with how i make it to alt tab me to a process name or window application name?

while($true){ Add-Type -AssemblyName System.Windows.Forms [System.Windows.Forms.SendKeys]::SendWait('%{TAB}') sleep 5 }

  • 1
    It’s going to be almost impossible to bring the *correct* application to the foreground by automating alt-tab keystrokes - how do you know how many tabs you need to send at any given time? If you google your question you’ll find a number of examples of using Powershell to find a process by window title and invoking win32 api calls to bring it to the foreground - e.g. https://stackoverflow.com/a/12802050/3156906. That has a better chance of working - have a play with some of those and see how far you can get… – mclayton Jul 10 '23 at 23:09
  • yea I agree, I am trying a different approach with $wsh.AppActivate("the app i want") sleep 5 if ($wsh.AppActivate("nothing")){ $wsh.AppActivate("nothing")} else{ [System.Windows.Forms.SendKeys]::SendWait('%{TAB}')} sleep 5 But how can I make it use the current app/window application that I am on a bit more clean since it works that way but it cycles all alt tabs till last one i think or not sure? (in the if function) also sorry if the code looks nasty its my first time using stack and I am not sure yet how to properly write it – Nasty Earl Jul 10 '23 at 23:28

1 Answers1

0

You can use Win + [Number] to open an application from your taskbar directly.

vycdev
  • 29
  • 1
  • 6
  • 1
    I don't wanna start an application, I want it to cycle to that specific application tab that is opened already instead of the first 2 most recent tabs at a set interval – Nasty Earl Jul 10 '23 at 20:00
  • If the application is already open then it will switch to it. – vycdev Jul 11 '23 at 16:41
  • yes but I want to cycle to it every 6-7 minutes not to just manually swap to it if you understand – Nasty Earl Jul 11 '23 at 21:23
  • So you can't simulate that cycling with your script by instead of alt tabbing you use win + number? – vycdev Jul 14 '23 at 09:34
  • No I figured it out how to make it work but the issue is that now I want it to alt tab back to my current tab and I am not sure how it works if you could help me out kindly, here is the script: Add-Type -AssemblyName System.Windows.Forms $wsh = New-Object -ComObject Wscript.shell while($true){ $wsh.AppActivate("MyAppName") sleep 0.2 if ($wsh.AppActivate("ecd")){ $wsh.AppActivate("ecd")} else{ [System.Windows.Forms.SendKeys]::SendWait('%{TAB}')} sleep 460 } – Nasty Earl Jul 17 '23 at 20:33