1

I want an Autohotkey script which launches a new instance of Chrome and brings that new window to the forefront (active window).

My script is:

#c::
Run "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -start-maximized --new-window www.google.com
WinActivate, Google ; Window title is "Google"

What happens is this: if, prior to activating the hotkey there is any arbitrary window in focus, the browser instance launches in the background which is not what I want. If however the desktop or Taskbar has focus then my new Chrome window comes to the forefront as I want it to.

  • 1. What happens if you just launch Chrome without any params? 2. Try specifying #WinActivateForce at the top of your script. – Karan Apr 26 '13 at 23:55
3

Most likely WInactivate does not work because you need to add SetTitleMatchMode, 2 at the top of your script. To test if WinActivate really works use this:

SetTitleMatchMode, 2
#c::
Run "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -start-maximized --new-window www.google.com
WinWait, google ;Give Chrome a chance to start before testing
IfWinExist, google
{
    WinActivate, google ; Window title is "Google"
    MessageBox, OK
}
Return

If you do NOT see the OK message, your Winactivate still waits for the correct title. Once you are sure this works, you can reduce is back to:

SetTitleMatchMode, 2
#c::
Run "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -start-maximized --new-window www.google.com
WinWait, google ;Give Chrome a chance to start before testing
WinActivate, google ; Window title is "Google"
Return
| improve this answer | |
  • librink - I was wrong - still sporadic. – Matthew Apr 26 '13 at 17:47
  • Matt, Still sporadic what?Doesn't Chrome launch, is Google.com not showing, or is your "Google" window not activated? B.t.w. As far as I know even with SetTitleMatchMode, 2 WinActivate is still case sensitive. – Robert Ilbrink Apr 27 '13 at 5:07
  • My question was poorly worded. I have fixed it. I am reading your answer - I am not sure if this would work in the common case where I have many Chrome windows (and instances) at the time I hit the hotkey. I might have to set a unique window title if I can and activate that. – Matthew Apr 28 '13 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.