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

Suggestions, feature requests and bug reports.
Post Reply
Thomas
Posts: 4
Joined: Mar 19th, ’14, 10:40

Post by Thomas » Dec 7th, ’16, 12:49

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
ChrisKey
Posts: 5
Joined: Dec 7th, ’16, 14:58

Post by ChrisKey » Dec 7th, ’16, 15:03

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.
User avatar
Tom
Posts: 791
Joined: Nov 24th, ’15, 23:39

Post by Tom » Dec 7th, ’16, 20:05

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.
User avatar
Ennovy
Posts: 70
Joined: Mar 18th, ’14, 08:46

Post by Ennovy » Dec 8th, ’16, 09:00

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.
Post Reply