Suggestions on how to implement custom search engines in Safari?

Hi all,

Safari 13 disables extensions like omnikey that allow a user to type "w arping" that expand into a wikipedia search url like "https://en.wikipedia.org/wiki/Special:Search/arping".

I was wondering how feasible it would be to intercept the "enter down" event in the URL bar, copy the text to the clipboard, check to see if it matches the pattern, then expand the URL and paste it back in and press enter.

In particular, does anyone have an idea of how to detect when "enter down" happens within the search/url box, rather than in forms and the like within a webpage?

Thanks!

How about macro activated by a hotkey in your browser that displays a Prompt for User Input field for your search string, which you would enter just like Omnikey? Subsequent actions would expand the search string to go to a new tab in your browser with the expanded search URL.

Rather than using any type of hotkey or "key down", I'd suggest using a Typed String trigger in a Macro that is in a Macro Group activated ONLY for the Web Browsers of interest.

Since this can not determine if you are actually in the Browser Address bar, you need to choose a Typed String prefix that you will only use with in the Address Bar.

In this case I'd use a Typed String with RegEx, maybe something like this:
;w\.(.+)๐–
where "๐–" is the SPACE character

Use that for both the trigger, and then in a Search using Regular Expression action to set a KM Variable (like "Local__SearchStr") to the first Capture Group.

Using your example:

type "w arping" that expands into a wikipedia search url like "arping - Wikipedia".

you would type:
;w.arping๐–

to get "arping" as the search term.

Assuming that you set the KM Variable "Local__SearchStr" to the first Capture Group, then use the KM Open a URL action, with this as the parameter for that Action:
https://en.wikipedia.org/wiki/Special:Search/%Local__SearchStr%

Of course, you can use whatever URL search root you wish.

FWIW, I use this format of ";" as the prefix and "๐–" as the suffix to trigger all of my typed string macros, and text expansion snippets with Typinator. This works very well to ensure no false positives.

Make sense?

1 Like

By the way DuckDuckGo defines โ€œ!wโ€ for a Wikipedia search. You might want to consider it as a search engine.

They call these โ€œ!Bangsโ€. The most useful one without any doubt is !kmf
(In case anyone doesnโ€™t know).

2 Likes

I have qqkm, qqkf, qqkw KM text expansions
for Keyboard Maestro, Keyboard Maestro Forum and Keyboard Maestro Wiki.

I want to get a seamless experience, get it to work as close to the native safari search as possible. Probably the best option would be to use some kind of extension here, but for now I'm trying this approach with redirects from built in search to a custom Redirect URL