jacob
jacob

Reputation: 820

Switch to last chrome window

#.::
IfWinExist Chrome
    WinActivate
else
    Run Chrome
return

Works just fine when the Chrome application is not running (i.e., when I just started my computer). But when chrome is running, it does not behave like I want to. It simply creates a new window. If I have a certain Chrome window active, then it creates a new window on top of that. If, however, I run Notepad and hit #. then a new window is created in the background, and I am still facing Notepad.

(I 'veread http://www.autohotkey.com/board/topic/7129-run-a-program-or-switch-to-an-already-running-instance/)

What I want to do, is to switch to the previous chrome window just as if I used #{tab}. And if there is no chrome window active, then and only then I wish to open a new one.

Upvotes: 3

Views: 1915

Answers (1)

576i
576i

Reputation: 8352

This will work.

Shortcut for a new tab is Ctrl-T.

There's no simple way of finding out if the tab is empty so I go to the address bar and look if that is empty by copying it to the clipboard.

You need to change the run command to point to chrome in your language version of windows. Also when I start chrome with run, it opens some old tabs.

#.::

SetTitleMatchMode, 2
IfWinExist, Google Chrome
    WinActivate, Google Chrome
else
    Run, "c:\programme\Google\Chrome\Application\chrome.exe"

WinWaitActive, Google Chrome
Send, ^l
Sleep, 200
Clipboard  =
Send, ^c
Sleep, 200
MyClip = %Clipboard%
If (MyClip <> "")
{       
  Send, ^t
}  
return

Upvotes: 2

Related Questions