diff --git a/modules/launcher.lua b/modules/launcher.lua index de15fa1..f1a524f 100644 --- a/modules/launcher.lua +++ b/modules/launcher.lua @@ -32,35 +32,27 @@ end) function bindAppWithHotkey(keyAppPairs,modifierKey) -- hs.alert.show("modifierKey,key: " .. modifierKey .. "," .. keyAppPairs ..) -- 确保MODIFIER_KEY已经被传递进来或在这里定义,例如MODIFIER_KEY = {"cmd", "alt"} - for key, app in pairs(keyAppPairs) do + for key, target in pairs(keyAppPairs) do hs.hotkey.bind(modifierKey, key, function() + hs.alert.show("" .. target) -- 如果是以http前缀的,就是网址,需要使用 Chrome 打开 - if string.find(app, "^http") then -- 使用'^http'来确保字符串以http开始 - hs.alert.show("URL: " .. app) - local url = app + if string.find(target, "^http") then -- 使用'^http'来确保字符串以http开始 + -- hs.alert.show("URL:" .. target) + local url = target 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,也可以传入路径 + elseif string.find(target, "app$") then -- 其它都当APP 处理 + -- hs.alert.show("APP:" .. target) + hs.application.launchOrFocus(target) -- 这种可以只传入app name,也可以传入路径 return + else + hs.alert.show("未知类型:" .. target) 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) \ No newline at end of file +-- 这里绑定 +bindAppWithHotkey(KEY_APP_PAIRS,MOFIFER_KEY) \ No newline at end of file