hammerspoon
hammerspoon copied to clipboard
hs.urlevent: Fix multiple query params and pass in fullURL to hs.urlevent's bind callback
Hi, I'm trying to implement something very similar to https://bargsten.org/wissen/custom-protocol-handler-macos/ to open links in the default browser, from within a Chrome PWA. I use the bind url handler to have hammerspoon open a URL in the default browser. The lua script for this handler is very simple and is as follows
hs.urlevent.bind("myevent", function(eventName, params)
local ref = params["ref"]
if ref ~= nil then
-- log.i('Ref is ' .. ref)
hs.execute("open " .. ref)
end
end)
I noticed two problems when using it:
- If the URL already has a query param, then the callback does not get any param for
ref
. https://example.com/ -> works https://example.com?k=v -> does not work - To have more freedom for the callback handler, would it be possible to pass in the full URL directly to the callback, instead of only propagating the parsed query params? I see that we do have the value at https://github.com/Hammerspoon/hammerspoon/blob/56b5835dc1bf7bb430dfea3f1662379cccec0c82/extensions/urlevent/urlevent.lua#L77 This way, even if issue 1 is not fixed, I can handle that case in my handler code