hammerspoon/modules/launcher.lua

66 lines
3.0 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- http://qtdebug.com/mac-hammerspoon/
-- 键和应用对
-- 提示: 数字作为键,需要使用 [Number] 的格式
local KEY_APP_PAIRS = {
[5] = "QSpace Pro.app",
Q = "QQ.app",W = "WeChat.app",E = "Microsoft Edge.app",T = "iTerm.app",I = "IINA.app",O = "Obsidian.app", P = "/Users/tanpengsccd/Applications/JetBrains Toolbox/PyCharm Professional Edition.app",
A = "ILink.app", S = "Surge.app",F = "/System/Volumes/Data/Applications/Apifox.app" ,G = "https://ai.h6.work",K = "Spotify.app", L = "NeteaseMusic.app",
Z = "QSpace Pro.app",X = "Xcode.app",C = "Google Chrome.app",V = "Visual Studio Code.app",B="iTerm.app",N = "Notes.app",M = "Telegram.app", -- B = "wechatwebdevtools.app"*/
-- [2] = "Notable.app",
-- [3] = "Typora.app",
}
-- 修饰键 这里设置为 f19
local MOFIFER_KEY = f19
-- local MOFIFER_KEY = "alt"
-- 显示 Finder:
hs.hotkey.bind(MOFIFER_KEY, "1", function()
hs.application.open("/System/Library/CoreServices/Finder.app")
hs.application.get("com.apple.finder"):setFrontmost(true)
end)
-- 重新加载配置
hs.hotkey.bind(f19, "R", function()
hs.reload()
end)
--------------------------------------------------------------------------------------
-- 按下 "F19+键" 会打开或激活对应的应用,如果应用不是绝对路径,则指的是 /Applications 中的应用 --
--------------------------------------------------------------------------------------
function bindAppWithHotkey(keyAppPairs,modifierKey)
-- hs.alert.show("modifierKey,key: " .. modifierKey .. "," .. keyAppPairs ..)
-- 确保MODIFIER_KEY已经被传递进来或在这里定义例如MODIFIER_KEY = {"cmd", "alt"}
for key, app in pairs(keyAppPairs) do
hs.hotkey.bind(modifierKey, key, function()
-- 如果是以http前缀的就是网址,需要使用 Chrome 打开
if string.find(app, "^http") then -- 使用'^http'来确保字符串以http开始
hs.alert.show("URL: " .. app)
local url = app
local scriptPath = os.getenv("HOME") .. "/.hammerspoon/jxa/openInChrome.jxa" -- 使用环境变量获取用户目录
local command = "osascript -l JavaScript " .. scriptPath .. " '" .. url .. "'"
hs.execute(command)
return
else -- 检查字符串是否以.app结束
hs.alert.show("Launching: " .. app)
hs.application.launchOrFocus(app) -- 这种可以只传入app name,也可以传入路径
return
end
end)
end
end
bindAppWithHotkey(KEY_APP_PAIRS,MOFIFER_KEY)
-- hs.hotkey.bind(MOFIFER_KEY, "G", function()
-- local url = "https://ai.h6.work" -- 无法打开 https
-- -- hs.alert.show(url)
-- local scriptPath = "~/.hammerspoon/jxa/openInChrome.jxa" -- 替换为你的JXA脚本实际路径
-- local command = "osascript -l JavaScript " .. scriptPath .. " '" .. url .. "'"
-- hs.execute(command)
-- -- hs.alert.show(command)
-- -- hs.alert.show("Script executed")
-- end)