feat: 优化代码
This commit is contained in:
parent
b83574c3e0
commit
2f948e13fb
@ -32,35 +32,27 @@ end)
|
|||||||
function bindAppWithHotkey(keyAppPairs,modifierKey)
|
function bindAppWithHotkey(keyAppPairs,modifierKey)
|
||||||
-- hs.alert.show("modifierKey,key: " .. modifierKey .. "," .. keyAppPairs ..)
|
-- hs.alert.show("modifierKey,key: " .. modifierKey .. "," .. keyAppPairs ..)
|
||||||
-- 确保MODIFIER_KEY已经被传递进来或在这里定义,例如MODIFIER_KEY = {"cmd", "alt"}
|
-- 确保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.hotkey.bind(modifierKey, key, function()
|
||||||
|
hs.alert.show("" .. target)
|
||||||
-- 如果是以http前缀的,就是网址,需要使用 Chrome 打开
|
-- 如果是以http前缀的,就是网址,需要使用 Chrome 打开
|
||||||
if string.find(app, "^http") then -- 使用'^http'来确保字符串以http开始
|
if string.find(target, "^http") then -- 使用'^http'来确保字符串以http开始
|
||||||
hs.alert.show("URL: " .. app)
|
-- hs.alert.show("URL:" .. target)
|
||||||
local url = app
|
local url = target
|
||||||
local scriptPath = os.getenv("HOME") .. "/.hammerspoon/jxa/openInChrome.jxa" -- 使用环境变量获取用户目录
|
local scriptPath = os.getenv("HOME") .. "/.hammerspoon/jxa/openInChrome.jxa" -- 使用环境变量获取用户目录
|
||||||
local command = "osascript -l JavaScript " .. scriptPath .. " '" .. url .. "'"
|
local command = "osascript -l JavaScript " .. scriptPath .. " '" .. url .. "'"
|
||||||
hs.execute(command)
|
hs.execute(command)
|
||||||
return
|
return
|
||||||
else -- 检查字符串是否以.app结束
|
elseif string.find(target, "app$") then -- 其它都当APP 处理
|
||||||
hs.alert.show("Launching: " .. app)
|
-- hs.alert.show("APP:" .. target)
|
||||||
hs.application.launchOrFocus(app) -- 这种可以只传入app name,也可以传入路径
|
hs.application.launchOrFocus(target) -- 这种可以只传入app name,也可以传入路径
|
||||||
return
|
return
|
||||||
|
else
|
||||||
|
hs.alert.show("未知类型:" .. target)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- 这里绑定
|
||||||
bindAppWithHotkey(KEY_APP_PAIRS,MOFIFER_KEY)
|
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)
|
|
Loading…
Reference in New Issue
Block a user