Page 1 of 1

"switch" to google chrome instead of start 2nd instance

Posted: Dec 7th, ’16, 12:49
by Thomas
I like to switch to a running chrome session by e.g. pressing "ooo" (like the calc example).
If chrome already is running, I like to switch to it at the present tab-folder.
If chrome is closed - simply this shortcut should start chrome.

In the moment I don't have a good idea.
normally in a batch I would check the running tasks.
How is it possible by ahk?

br - thomas

Re: "switch" to google chrome instead of start 2nd instance

Posted: Dec 7th, ’16, 15:03
by ChrisKey
I use something like this...

Code: Select all

THEapp:="Total Commander"

IfWinExist, %THEapp%
  IfWinNotActive
     WinActivate
  else {
		WinGet, numCountWindows, Count, %THEapp%
		if (numCountWindows>1) { ;more than one open window -> cycle
			WinGetClass, ActiveClass, A
			WinSet, Bottom,, A
			WinActivate, ahk_class %ActiveClass%
		}
		else {
			WinMinimize
		}
	}
else {
	run C:\...\TOTALCMD.EXE
}
This script does a little bit more than you asked for.
I use it for every application that I start frequently.

If the app is not already started => it starts the app.
If the app is started but doesn't have the focus => brings the app to the foreground.
If the app has the focus and there are more than one window of this app => it cycles through the open windows.
If the app has the focus (only one window) => it minimises the app.

Re: "switch" to google chrome instead of start 2nd instance

Posted: Dec 7th, ’16, 20:05
by Tom
This works for me:
String: ooo
Type: Command
Substitute:

Code: Select all

IfWinNotExist ahk_exe chrome.exe
   run, "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
WinWait, ahk_exe chrome.exe
WinActivate, ahk_exe chrome.exe
You may need to adapt the Chrome path to your Windows version.

Re: "switch" to google chrome instead of start 2nd instance

Posted: Dec 8th, ’16, 09:00
by Ennovy
ChrisKey wrote:

I use something like this...

Code: Select all

THEapp:="Total Commander"

IfWinExist, %THEapp%
  IfWinNotActive
     WinActivate
  else {
		WinGet, numCountWindows, Count, %THEapp%
		if (numCountWindows>1) { ;more than one open window -> cycle
			WinGetClass, ActiveClass, A
			WinSet, Bottom,, A
			WinActivate, ahk_class %ActiveClass%
		}
		else {
			WinMinimize
		}
	}
else {
	run C:\...\TOTALCMD.EXE
}
This script does a little bit more than you asked for.
I use it for every applikation that I start frequently.

If the app is not already started => it starts the app.
If the app is started but doesn't have the focus => brings the app to the foreground.
If the app has the focus and there are more than one window of this app => it cycles through the open windows.
If the app has the focus (only one window) => it minimises the app.
Thanks, I can use this.