1

I would like to setup a keyboard shortcut/hotkey that would switch to Google Chrome and go to the omnibox (address bar). I intend to use it invoke various custom search engines.

I found a couple of related questions but not quite there:

I had done something like this with AutoHotKey on Windows. What's the right tool on the Mac?

I am already using Karabiner-Elements and Alfred.

  • I found https://karabiner-elements.pqrs.org/docs/json/typical-complex-modifications-examples/#open-alfred-4-if-escape-is-held-down and set up a hotkey to switch to Google Chrome. However, I'm missing the last step -- how to put the cursor into the Address Bar. – Aleksey Tsalolikhin Mar 16 '21 at 18:45
  • 1
    Most browsers use Cmd/L – Tetsujin Mar 16 '21 at 18:51
  • Yes -- can I have Karabiner send Cmd/L to the browser for me? – Aleksey Tsalolikhin Mar 16 '21 at 18:52
  • You could add activate "Google Chrome" to the head of the raise script, & keystroke "l" with command down to the end, then all you need do is add a keystroke for the whole thing saved as a Service. No 3rd party app required. – Tetsujin Mar 16 '21 at 19:02
  • Thank you! Is https://apple.stackexchange.com/questions/39204/script-to-raise-a-single-window-to-the-front the raise script? How do I save the thing as a Service? (Total noob question.) In the meantime, I found if I use open -n -a 'Google Chrome.app' in Karabiner, I get the desired effect as well. – Aleksey Tsalolikhin Mar 16 '21 at 19:08
  • open -n -a ... is a little slow though... takes longer to launch a new instance of Chrome than to open the current instance. =) – Aleksey Tsalolikhin Mar 16 '21 at 19:11

1 Answers1

1

I think your task is ill-defined & what you have found so far overkill - (that this is because you are new to Mac means that's nothing to be ashamed of, we all start somewhere;) If all you need is to bring an app to the front & enable the location area you can do it in Applescript in 2 lines.

tell application "Google Chrome" to activate
tell application "System Events" to keystroke "l" using command down

perhaps with an optional delay 0.5 in between those lines in case it's a bit slow to come to the front.

The only difficulty is to make this key-commandable.

If you set this up as a Script event in Automator, then in previous OSes [I think up to Mojave, I haven't used anything newer] you could just define it as a Service. Once defined & saved, you can then call the Service using
System Prefs > Keyboard > Shortcuts > Services
I think this has changed since Catalina, but someone else would need to detail precisely how.
So long as you give it a shortcut that doesn't conflict with anything else, then simply hitting that shortcut will bring Chrome to the front [or launch it if it's not already running] & set the cursor into the search/location bar. It will do this on the current tab if one is already open, or make a new window if nothing was open.

Tetsujin
  • 115,663
  • Yay! Thank you, thank you, thank you @Tetsujin! That did it. Just like you said. Here is a link to the documentation: https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/MakeaSystem-WideService.html This worked on Catalina. – Aleksey Tsalolikhin Mar 18 '21 at 23:13
  • 1
    Glad you got it. I wasn't certain the Automator method was still valid after Mojave. Glad it worked:) – Tetsujin Mar 19 '21 at 09:32