How to override browser keyboard shortcut?

I would like Cmd+S to click on a button in Chrome for webpages that have a specific string in their URL.

Here is my attempt:

When I press Cmd+S, browser's Save dialog comes up. Is there a way to have this trigger my macro?

You could try and assign a different shortcut to Save and Save As... via System Preferences > Keyboard > Shortcuts > App Shortcuts and see if that helps, but I can't be sure.

You could also try and replace the Move and Click action with a Set Variable to Google Chrome Field action, followed by an Execute a JavaScript in Google Chrome action. The Set Variable... action will populate a drop-down list with HTML DOM objects that it finds in the currently active tab of Chrome (so navigate to one of these pages containing that text, and see if the button can be identified). Once it's stored in a variable, you can use it in the Execute... action, and issue a click().

I want Cmd + S to run my macro only when Chrome URL contains a specific string. For others, it should do the default.

I have actually replaced "Move and Click.." action with a "Click Google Chrome Link" action and specified the XPath.

As a matter of interest why do you want to override standard Cmd+S behaviour? Might be better to pick another hot key or else an augmented version of Cmd+S such as Cmd+Carl+S.

I build websites. There's a WordPress plugin called Oxygen which provides an interface that looks like this:

It can get tedious trying to move my mouse around, collapse panels, expand etc. to get to the element that I want to add in the editor. I am adding macros for all the interface buttons so I can simulate clicks by searching for the function name and hitting enter.

I hardly ever use the browser's save dialog. Hence why want to have Cmd+S click on the Save button at the top far right in the first screenshot.

For the macro to know that the Chrome URL contains a specific string, it has to run. If the string is present, the macro will then know it can continue running as normal; if the string isn't found, it would either terminate early, or trigger the normal function of the ⌘S shortcut.

But, my feeling is that, if you wish the browser's regular save dialog to appear in all other situations where the URL doesn't contain the string, it will likely have to fall on your macro to initiate this. If the browser shortcut is interfering with your macro shortcut, and there's no flexibility in using a different hotkey, then you have to remove the default browser shortcut.

One idea worth mentioning would be to create a macro group for this macro specially, and dictate that it is Availabe in these applications (Chrome only) and Available when a focused window title is/contains (which you could set to the title of Chrome window in which the Oxygen interface is running).

But this doesn't solve your issue of shortcut interference.

Then why do you wish to retain its default functionality at other times ?

I just created my own macro for Chrome using ⌘S, and it works as you would expect/want: the macro triggers; the browser's Save dialog does not appear.

I wonder why it would operate one way on my system, and a different way on yours...?

Hey @Sridhar,

Hmm... As @CJK mentions this should work.

If you install by double-clicking in the Finder and make certain both the macro and macro group are enabled – it should work.

Trap Command-S in Google Chrome.kmmacros (6.0 KB)

If things are still not working try using the “Assistance” (troubleshooting wizard) in the Help menu.

Let us know what happens.

-Chris

1 Like

Not sure what I am doing differently, but the following is working for me now.

@CJK @ccstone Thanks a lot.

1 Like