2
votes
#.::
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.

1
If AHK "complains", it could be helpful if you specified about what. I believe it would help if you made clear to yourself, what the difference between an active, inactive, and non-existing window is, and also, what the difference between an application/process and a window is. You are using running as the opposite of not activated, but the former relates to an application and the latter relates to a window. So please revise your question with special consideration of the terminology. - MCL

1 Answers

2
votes

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