hammerspoon/modules/launcher.lua
sugood 419b09e2ce v0.1.6
1、新增系统日历快捷键,更换打开chrome的快捷键
2、优化状态栏信息显示逻辑,防止断网异常
3、系统信息状态栏显示日期,并且能快速获取日期时间,格式:YYYY-MM-DD hh:mm:ss
2022-01-15 21:38:51 +08:00

47 lines
1.4 KiB
Lua

local hotkey = require "hs.hotkey"
local grid = require "hs.grid"
local window = require "hs.window"
local application = require "hs.application"
local appfinder = require "hs.appfinder"
local fnutils = require "hs.fnutils"
grid.setMargins({0, 0})
applist = {
{shortcut = 'A',appname = 'Launchpad'},
{shortcut = 'C',appname = 'calendar'},
{shortcut = 'D',appname = 'Disk Utility'},
{shortcut = 'E',appname = 'Finder'},
{shortcut = 'G',appname = 'Google Chrome'},
{shortcut = 'Q',appname = 'Activity Monitor'},
{shortcut = 'T',appname = 'Terminal'},
{shortcut = 'S',appname = 'System Preferences'},
{shortcut = 'Z',appname = 'Calculator'},
}
fnutils.each(applist, function(entry)
hotkey.bind({'ctrl', 'shift'}, entry.shortcut, entry.appname, function()
application.launchOrFocus(entry.appname)
-- toggle_application(applist[i].appname)
end)
end)
-- Toggle an application between being the frontmost app, and being hidden
function toggle_application(_app)
local app = appfinder.appFromName(_app)
if not app then
application.launchOrFocus(_app)
return
end
local mainwin = app:mainWindow()
if mainwin then
if mainwin == window.focusedWindow() then
mainwin:application():hide()
else
mainwin:application():activate(true)
mainwin:application():unhide()
mainwin:focus()
end
end
end