-
-
Save cornradio/e46fc1fefa769833e6cfdeb3fbb54f3b to your computer and use it in GitHub Desktop.
hammerspoon.lua
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
-- http://www.hammerspoon.org/go/ 新手教程 | |
-- http://www.hammerspoon.org/docs/hs.application.html 全部文档 | |
-- hs.hotkey.bind({"cmd", "alt", "ctrl"}, "W", function() | |
-- hs.alert.show("Hello World!") | |
-- end) | |
-- url encode 和decode函数 | |
local function urlEncode(s) | |
s = string.gsub(s, "([^%w%.%- ])", function(c) return string.format("%%%02X", string.byte(c)) end) | |
return string.gsub(s, " ", "+") | |
end | |
local function urlDecode(s) | |
s = string.gsub(s, '%%(%x%x)', function(h) return string.char(tonumber(h, 16)) end) | |
return s | |
end | |
-- 从剪贴板获取内容并模仿打字出来 | |
hs.hotkey.bind({"cmd", "alt"}, "V", function() hs.eventtap.keyStrokes(hs.pasteboard.getContents()) end) | |
-- 自动重新加载config | |
function reloadConfig(files) | |
doReload = false | |
for _,file in pairs(files) do | |
if file:sub(-4) == ".lua" then | |
doReload = true | |
end | |
end | |
if doReload then | |
hs.reload() | |
end | |
end | |
myWatcher = hs.pathwatcher.new(os.getenv("HOME") .. "/.hammerspoon/", reloadConfig):start() | |
hs.alert.show("Config loaded") | |
-- hs.hotkey.bind({"ctrl"}, "q", function() | |
-- hs.notify.new({title="ctrl Q", informativeText="调用系统截图"}):send() | |
-- end) | |
-- 搜索功能 | |
hs.hotkey.bind({"cmd", "alt"}, "2", function() | |
local clipboardText = tostring(hs.pasteboard.getContents()) | |
-- print("what is in the clipboard?:a"..clipboardText) | |
hs.notify.new({title="百度搜索", informativeText=clipboardText}):send() | |
hs.urlevent.openURL("https://www.baidu.com/s?wd="..urlEncode(clipboardText)) | |
end) | |
hs.hotkey.bind({"cmd", "alt"}, "3", function() | |
local clipboardText = tostring(hs.pasteboard.getContents()) | |
hs.notify.new({title="谷歌搜索", informativeText=clipboardText}):send() | |
hs.urlevent.openURL("https://www.google.com/search?q="..urlEncode(clipboardText)) | |
end) | |
hs.hotkey.bind({"cmd", "alt"}, "0", function() | |
local clipboardText = tostring(hs.pasteboard.getContents()) | |
hs.notify.new({title="打开url", informativeText=clipboardText}):send() | |
hs.urlevent.openURL(clipboardText) | |
end) | |
hs.hotkey.bind({"cmd", "alt"}, "4", function() | |
local clipboardText = tostring(hs.pasteboard.getContents()) | |
hs.notify.new({title="You搜索", informativeText=clipboardText}):send() | |
hs.urlevent.openURL("https://you.com/search?q="..urlEncode(clipboardText)) | |
end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "c", function() | |
hs.notify.new({title="前往快速剪切板", informativeText="netcut.cn/kasusa"}):send() | |
hs.urlevent.openURL("https://netcut.cn/kasusa") | |
end) | |
hs.hotkey.bind({"cmd", "alt"}, "5", function() | |
-- 使用hs复制选中内容到剪切板,然后再读取剪切板内容,然后打开iterm并执行命令 | |
hs.eventtap.keyStroke({"cmd"}, "c") | |
local clipboardText = tostring(hs.pasteboard.getContents()) | |
hs.notify.new({title="执行命令", informativeText=clipboardText}):send() | |
hs.application.open("Terminal.app") | |
hs.eventtap.keyStrokes(clipboardText.."\r") | |
end) | |
-- hs.hotkey.bind({"cmd"}, "3", function() | |
-- local clipboardText = tostring(hs.pasteboard.getContents()) | |
-- hs.urlevent.openURL("https://www.youtube.com/results?search_query="..urlEncode(clipboardText)) | |
-- end) | |
-- load some app using hotkey | |
hs.hotkey.bind({"cmd", "shift"}, "space", function() hs.application.open("Shadowrocket.app") end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "t", function() hs.application.open("Warp.app") end) | |
-- hs.hotkey.bind({"cmd", "ctrl"}, "s", function() hs.application.open("SigmaOS.app") end) | |
-- hs.hotkey.bind({"cmd", "ctrl"}, "s", function() hs.application.open("Siri.app") end) | |
hs.hotkey.bind({"cmd","alt", "ctrl"}, "t", function() hs.application.open("Telegram.app") end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "w", function() hs.application.open("WeChat.app") end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "v", function() hs.application.open("Visual Studio Code.app") end) | |
hs.hotkey.bind({"cmd", "alt"}, "e", function() hs.application.open("Finder.app") end) | |
hs.hotkey.bind({"cmd", "alt"}, "k", function() hs.application.open("keepassxc.app") end) | |
hs.hotkey.bind({"cmd", "alt"}, "o", function() hs.application.open("obsidian.app") end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "j", function() hs.eventtap.keyStrokes("Jinghaoyang1") end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "1", function() hs.eventtap.keyStrokes("1292396652@qq.com") end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "3", function() hs.eventtap.keyStrokes("18816528960") end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "k", function() hs.eventtap.keyStrokes("kasusaland@gmail.com") end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "b", function() hs.eventtap.keyStrokes("443=})7'n8EjA97$F?GijB[,]F4T~D\"4") end) | |
hs.hotkey.bind({"cmd","alt"},"return", function() hs.eventtap.keyStrokes("1567890") end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment