Skip to content

Instantly share code, notes, and snippets.

@Glyphack
Created December 29, 2023 11:47
Show Gist options
  • Save Glyphack/c27e4b943214b883c87f9726d2dd042c to your computer and use it in GitHub Desktop.
Save Glyphack/c27e4b943214b883c87f9726d2dd042c to your computer and use it in GitHub Desktop.
Redirect URLs with Hammerspoon
-- Define the Lua table that maps names to URLs
local urlTable = {
john = "https://example.com/john",
alice = "https://example.com/alice",
bob = "https://example.com/bob",
}
-- Register a callback for the custom hammerspoon:// URLs
hs.urlevent.bind("example", function(eventName, params, senderPID)
local event = eventName -- The event name is the host in hammerspoon://host
local name = params["name"]
local matchedLink = urlTable[name]
if name and matchedLink then
hs.urlevent.openURL(matchedLink)
else
print("name not found or no action specified.")
print(event, name)
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment