Created
December 29, 2023 11:47
-
-
Save Glyphack/c27e4b943214b883c87f9726d2dd042c to your computer and use it in GitHub Desktop.
Redirect URLs with Hammerspoon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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