changing hotkey action depend on which chrome profile is currently active Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
vkhu
Posts: 10
Joined: 04 Oct 2018, 00:40

changing hotkey action depend on which chrome profile is currently active

27 Apr 2022, 02:31

Due to my work, I often have a lot of chrome profiles open simultaneously, and I want to make a single set of hotkey perform different action depend on which profile is currently active.
To better illustrate the point, the final code would look something like this:

Code: Select all

$^+x::
If WinActive("ahk_exe chrome.exe")
	{
		If <Profile 1 is active>
			{
				FileEncoding, UTF-8
				FileRead, Clipboard, %UserProfile%\Dropbox\AutoHotkey Automation Scripts\Insert TXT\CannedResponse.txt
				Sleep, 10
				Send, ^{v}
				Return
			}
		If <Profile 2 is active>
			{
				Send, ^{w}
				Return
			}
		If <Profile 3 is active>
			{
				MouseClick, left, 40, 25
				Return
			}
	}
Send, ^+x
Return
The problem is ahk doesn't seem to have any built-in way to tell the different profiles apart. Their ahk_exe, ahk_class, ahk_pid, wintext are all exactly the same. I can't rely on WinTitle, since it changes depend on which tab is currently in focus, and they can overlapped. I'm thinking of using the pixel color of the chrome profile avatar, but then if I resize the browser window or change the avatar image, it'd become useless.

Could someone help please?
User avatar
BrockPlaysFortnite
Posts: 84
Joined: 06 Nov 2021, 08:47

Re: changing hotkey action depend on which chrome profile is currently active  Topic is solved

27 Apr 2022, 11:51

ImageSearch would work regardless of window size and if you change the picture its as simple as replacing it in whatever folder you set the original one in. Also, since from what I can see the image never changes positions relative to the window it would be a very fast image search since all you have to search is that little square in the top right corner
Fortnite Youtuber BrockPlaysFortnite :D | AHK completely redefined the way I do things. What used to take me hours to do over and over can now be done with the click of a button. Don't give up! It's worth learning it front to back :wave:
(Note: I'm still a noob so my code may suck sometimes and there is almost assuredly a better way to do it)
Lefty777
Posts: 25
Joined: 04 Apr 2022, 23:16

Re: changing hotkey action depend on which chrome profile is currently active

27 Apr 2022, 13:37

Maybe there are better ways to do it, but I think your idea of using the color of the profile avatar would be straightforward and work pretty well. You could fairly easily get the window dimensions using WinGetPos and then use PixelGetColor using an expression based on the window dimension to always select a pixel within the avatar image. Or use ImageSearch to match the entire profile avatar. It would always be consistent no matter what size/position the window is. You would of course have to keep the avatar images constant to however you set it up, but it should work.

Even if you setup access to Chrome API through ahk with debugging protocol and additional ahk libraries, I do not believe there is any API function to query the current profile due to security purposes.

You could certainty use chrome.ahk to open a new tab link to "chrome://version/" which will list the profile path. This could be parsed into a variable for the active profile and then closed, but it would at best require a new tab opening to capture the active profile for each new tab/window you create and capture its hwnd for future commands because even the pid's of different open windows of chrome are the same.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Leonardo_Portela and 182 guests