Context sensitive for specific browser tabs works but multiple browsers covered?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
lawnmowerobot
Posts: 9
Joined: 21 Oct 2020, 04:04

Context sensitive for specific browser tabs works but multiple browsers covered?

Post by lawnmowerobot » 26 Jun 2022, 00:18

I like to use keyboard shortcuts but hard to remember them all. So the script below will show some keyboard shortcuts (most removed to keep short) for particular websites in Chrome. It works fine but sometimes I use other browsers so it would be handy to also get the keyboard shortcut reminders when using them also
I could of course duplicate for every other supported browser but it feels like there is probably a way to include the alternatives in the WinGetTitle line somehow
Tried lots of variations but nothing as yet has worked so would appreciate if someone who knows how to essentially OR in the WinGetTitle area could point out the method, Thanks LMR

Code: Select all

^9::
		
		WinGetTitle, WinT, ahk_exe Chrome.exe
        If InStr(WinT,"dynalist")
		{
			MsgBox, 
			(LTrim

			SEARCHING
			Ctrl f `t`t`t`t` Search in current document
			Ctrl f then Ctrl Enter `t`t` Search all			
			)
		}
			
	
		Else

		WinGetTitle, WinT, ahk_exe Chrome.exe
        If InStr(WinT,"Outlook")
		{
		MsgBox, 
			(LTrim
			
			Using Gmail shortcuts in Settings
			? - shortcuts
			Ctl a - select all messages
			Sft i - mark as read
			Sft u - mark as unread
			)

		}

[Mod edit: Added [code][/code] tags. Please use them yourself when posting code! Thank you.]

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: Context sensitive for specific browser tabs works but multiple browsers covered?

Post by boiler » 26 Jun 2022, 00:52

lawnmowerobot wrote: I could of course duplicate for every other supported browser but it feels like there is probably a way to include the alternatives in the WinGetTitle line somehow
You can set up a hotkey to be active only when one of the browser windows you specify is active. See GroupAdd and #IfWinActive. Within the hotkey routine, you can just get the title of the active window rather than having to specify the window by the browser’s WinTitle:

Code: Select all

WinGetTitle, WinT, A

lawnmowerobot
Posts: 9
Joined: 21 Oct 2020, 04:04

Re: Context sensitive for specific browser tabs works but multiple browsers covered?

Post by lawnmowerobot » 26 Jun 2022, 03:54

Thanks Boiler (again),

That sounds good although rather incomprehensible to my non-coding brain 🙃

Any chance you could quickly demo the code that would make it work? Would possibly be of interest to others also

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: Context sensitive for specific browser tabs works but multiple browsers covered?

Post by boiler » 26 Jun 2022, 07:22

Code: Select all

GroupAdd, Browsers, ahk_exe chrome.exe
GroupAdd, Browsers, ahk_exe firefox.exe

#IfWinActive ahk_group Browsers
^9::	
	
	WinGetActiveTitle, WinT
    If InStr(WinT,"dynalist")
	{
		MsgBox, 
		(LTrim

		SEARCHING
		Ctrl f `t`t`t`t` Search in current document
		Ctrl f then Ctrl Enter `t`t` Search all			
		)
	}
			
	Else
	{

		WinGetActiveTitle, WinT
        If InStr(WinT,"Outlook")
		{
    		MsgBox, 
			(LTrim
			
			Using Gmail shortcuts in Settings
			? - shortcuts
			Ctl a - select all messages
			Sft i - mark as read
			Sft u - mark as unread
			)

		}
	}
return

You also didn’t put braces around your else block of lines, so I fixed that. And I added a return at the end of your hotkey routine, which you should always do.

Or since you got the title before the first if, you don’t need to get it again since it gets it no matter which browser is active. So you can remove it from the bottom part, and it eliminates the need for a set of braces since the inner if counts as just one command. In fact, that would be true of all your braces in this case:

Code: Select all

GroupAdd, Browsers, ahk_exe chrome.exe
GroupAdd, Browsers, ahk_exe firefox.exe

#IfWinActive ahk_group Browsers
^9::	
	WinGetActiveTitle, WinT
    If InStr(WinT,"dynalist")
		MsgBox, 
		(LTrim

		SEARCHING
		Ctrl f `t`t`t`t` Search in current document
		Ctrl f then Ctrl Enter `t`t` Search all			
		)
			
	Else If InStr(WinT,"Outlook")
		MsgBox, 
		(LTrim
			
		Using Gmail shortcuts in Settings
		? - shortcuts
		Ctl a - select all messages
		Sft i - mark as read
		Sft u - mark as unread
		)
return

lawnmowerobot
Posts: 9
Joined: 21 Oct 2020, 04:04

Re: Context sensitive for specific browser tabs works but multiple browsers covered?

Post by lawnmowerobot » 26 Jun 2022, 18:24

Works beautifully thanks 🥇

Thanks Boiler very much for taking the time to do that

Post Reply

Return to “Ask for Help (v1)”