new: 大量修改

This commit is contained in:
谭鹏(深圳联友科技有限公司创新产品群数字营销产品中心) 2023-02-25 13:24:12 +08:00 committed by tanpengsccd
parent 6d7e11c238
commit 768e9ad516
6 changed files with 107 additions and 96 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
/*.zip /*.zip
.idea/ .idea/
build/ build/
.DS_Store

View File

@ -3,14 +3,15 @@ package.path = hs.configdir .. '/?.lua;' .. hs.configdir .. '/?/init.lua;' .. hs
require "modules/reload" require "modules/reload"
require "modules/hotkey" require "modules/hotkey"
require "modules/commons" -- require "modules/commons"
require "modules/system" -- require "modules/system"
require "modules/windows" require "modules/windows"
require "modules/launcher" require "modules/launcher"
require "modules/systemInfo" -- require "modules/systemInfo"
require "modules/snippet" -- require "modules/snippet"
require "modules/timesync" -- require "modules/timesync"
require "modules/caffeine" -- require "modules/caffeine"
require "modules/inputstat" -- require "modules/inputstat"
require "modules/dict" require "modules/dict"
require "modules/jsonFormat" -- require "modules/jsonFormat"

View File

@ -3,3 +3,4 @@ hyperShift = {"alt", "shift"}
hyperCtrl = {"alt", "ctrl"} hyperCtrl = {"alt", "ctrl"}
hyperAlt = {"ctrl", "alt", "shift"} hyperAlt = {"ctrl", "alt", "shift"}
hyperCmd = {"alt", "cmd"} hyperCmd = {"alt", "cmd"}
f19 = {'cmd','alt','shift','ctrl'}

View File

@ -1,46 +1,46 @@
local hotkey = require "hs.hotkey" -- http://qtdebug.com/mac-hammerspoon/
local grid = require "hs.grid" -- 键和应用对
local window = require "hs.window" -- 提示: 数字作为键,需要使用 [Number] 的格式
local application = require "hs.application"
local appfinder = require "hs.appfinder"
local fnutils = require "hs.fnutils"
grid.setMargins({0, 0}) local KEY_APP_PAIRS = {
[5] = "QSpace Pro.app",
Q = "QQ.app",W = "WeChat.app",E = "Microsoft Edge.app",T = "iTerm.app",Y = "语雀.app",U = "Notion.app",I = "IINA.app",O = "Obsidian.app", P = "Clash Verge.app",
A = "ILink.app",S = "WebStorm.app",F = "Finder.app",G = "ChatGPT.app",H = "HBuilderX.app",K = "Spotify", L = "NeteaseMusic.app",
Z = "QSpace Pro.app",X = "Xcode.app",C = "Google Chrome.app",V = "Visual Studio Code.app",B = "wechatwebdevtools.app",N = "/System/Applications/Notes.app",M = "Telegram.app",
applist = { -- [2] = "Notable.app",
{shortcut = 'A',appname = 'Launchpad'}, -- [3] = "Typora.app",
{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'},
} }
-- 修饰键 这里设置为 f19
local MOFIFER_KEY = f19
-- local MOFIFER_KEY = "alt"
fnutils.each(applist, function(entry) -- 显示 Finder:
hotkey.bind({'ctrl', 'shift'}, entry.shortcut, entry.appname, function() -- hs.hotkey.bind(MOFIFER_KEY, "1", function()
application.launchOrFocus(entry.appname) -- hs.application.open("/System/Library/CoreServices/Finder.app")
-- toggle_application(applist[i].appname) -- hs.application.get("com.apple.finder"):setFrontmost(true)
end) -- end)
-- 重新加载配置
hs.hotkey.bind(f19, "R", function()
hs.reload()
end) end)
-- Toggle an application between being the frontmost app, and being hidden --------------------------------------------------------------------------------------
function toggle_application(_app) -- 按下 "F19+键" 会打开或激活对应的应用,如果应用不是绝对路径,则指的是 /Applications 中的应用 --
local app = appfinder.appFromName(_app) --------------------------------------------------------------------------------------
if not app then function bindAppWithHotkey(keyAppPairs)
application.launchOrFocus(_app)
return
end -- 另一种方式
local mainwin = app:mainWindow() for key, app in pairs(keyAppPairs) do
if mainwin then hs.hotkey.bind(MOFIFER_KEY, key .. "", function()
if mainwin == window.focusedWindow() then -- hs.application.open(app) -- 这种方式必须要app 路径
mainwin:application():hide() hs.alert.show(app)
else hs.application.launchOrFocus(app) -- 这种可以只传入app name,也可以传入路径
mainwin:application():activate(true) end)
mainwin:application():unhide()
mainwin:focus()
end
end end
end end
bindAppWithHotkey(KEY_APP_PAIRS)

View File

@ -11,11 +11,12 @@ local fnutils = require "hs.fnutils"
local geometry = require "hs.geometry" local geometry = require "hs.geometry"
local mouse = require "hs.mouse" local mouse = require "hs.mouse"
local MOFIFER_KEY_HALF = f19
-- default 0.2 -- default 0.2
window.animationDuration = 0 window.animationDuration = 0.1
-- left half -- left half
hotkey.bind(hyper, "Left", function() hotkey.bind(MOFIFER_KEY_HALF, "Left", function()
if window.focusedWindow() then if window.focusedWindow() then
window.focusedWindow():moveToUnit(layout.left50) window.focusedWindow():moveToUnit(layout.left50)
else else
@ -24,37 +25,37 @@ hotkey.bind(hyper, "Left", function()
end) end)
-- right half -- right half
hotkey.bind(hyper, "Right", function() hotkey.bind(MOFIFER_KEY_HALF, "Right", function()
window.focusedWindow():moveToUnit(layout.right50) window.focusedWindow():moveToUnit(layout.right50)
end) end)
-- top half -- top half
hotkey.bind(hyper, "Up", function() hotkey.bind(MOFIFER_KEY_HALF, "Up", function()
window.focusedWindow():moveToUnit'[0,0,100,50]' window.focusedWindow():moveToUnit'[0,0,100,50]'
end) end)
-- bottom half -- bottom half
hotkey.bind(hyper, "Down", function() hotkey.bind(MOFIFER_KEY_HALF, "Down", function()
window.focusedWindow():moveToUnit'[0,50,100,100]' window.focusedWindow():moveToUnit'[0,50,100,100]'
end) end)
-- left top quarter -- left top quarter
hotkey.bind(hyperAlt, "Left", function() hotkey.bind(MOFIFER_KEY_HALF, "[", function()
window.focusedWindow():moveToUnit'[0,0,50,50]' window.focusedWindow():moveToUnit'[0,0,50,50]'
end) end)
-- right bottom quarter -- right bottom quarter
hotkey.bind(hyperAlt, "Right", function() hotkey.bind(MOFIFER_KEY_HALF, "'", function()
window.focusedWindow():moveToUnit'[50,50,100,100]' window.focusedWindow():moveToUnit'[50,50,100,100]'
end) end)
-- right top quarter -- right top quarter
hotkey.bind(hyperAlt, "Up", function() hotkey.bind(MOFIFER_KEY_HALF, "]", function()
window.focusedWindow():moveToUnit'[50,0,100,50]' window.focusedWindow():moveToUnit'[50,0,100,50]'
end) end)
-- left bottom quarter -- left bottom quarter
hotkey.bind(hyperAlt, "Down", function() hotkey.bind(MOFIFER_KEY_HALF, ";", function()
window.focusedWindow():moveToUnit'[0,50,50,100]' window.focusedWindow():moveToUnit'[0,50,50,100]'
end) end)
@ -69,7 +70,7 @@ hotkey.bind(hyper, 'C', function()
end) end)
-- maximize window -- maximize window
hotkey.bind(hyper, 'M', function() toggle_maximize() end) hotkey.bind(MOFIFER_KEY_HALF, 'return', function() window.focusedWindow(): maximize() end)
-- defines for window maximize toggler -- defines for window maximize toggler
local frameCache = {} local frameCache = {}
@ -86,34 +87,23 @@ function toggle_maximize()
end end
-- display a keyboard hint for switching focus to each window -- display a keyboard hint for switching focus to each window
hotkey.bind(hyperShift, '/', function() -- hotkey.bind(hyperShift, '/', function()
hints.windowHints() -- hints.windowHints()
-- Display current application window -- -- Display current application window
-- hints.windowHints(hs.window.focusedWindow():application():allWindows()) -- -- hints.windowHints(hs.window.focusedWindow():application():allWindows())
end) -- end)
-- switch active window -- switch active window
hotkey.bind(hyperShift, "H", function() -- hotkey.bind(hyperShift, "H", function()
window.switcher.nextWindow() -- window.switcher.nextWindow()
end) -- end)
-- move active window to previous monitor
hotkey.bind(hyperShift, "Left", function()
window.focusedWindow():moveOneScreenWest()
end)
-- move active window to next monitor -- move cursor to previous/next monitor
hotkey.bind(hyperShift, "Right", function() -- hotkey.bind(hyperCtrl, "Right", function ()
window.focusedWindow():moveOneScreenEast() -- focusScreen(window.focusedWindow():screen():previous())
end) -- end)
hotkey.bind(f19, "`", function ()
-- move cursor to previous monitor
hotkey.bind(hyperCtrl, "Right", function ()
focusScreen(window.focusedWindow():screen():previous())
end)
-- move cursor to next monitor
hotkey.bind(hyperCtrl, "Left", function ()
focusScreen(window.focusedWindow():screen():next()) focusScreen(window.focusedWindow():screen():next())
end) end)
@ -153,19 +143,37 @@ moveto = function(win, n)
end end
end end
-- cycled move active window to another screen
-- move cursor to monitor 1 and maximize the window hs.hotkey.bind( f19, 'tab', function()
hotkey.bind(hyperShift, "1", function() -- get the focused window
local win = window.focusedWindow() local win = hs.window.focusedWindow()
moveto(win, 1) -- get the screen where the focused window is displayed, a.k.a. current screen
local screen = win:screen()
-- compute the unitRect of the focused window relative to the current screen
-- and move the window to the next screen setting the same unitRect
win:move(win:frame():toUnitRect(screen:frame()), screen:next(), true, 0)
end) end)
hotkey.bind(hyperShift, "2", function() -- -- move active window to monitor 1 and maximize the window
local win = window.focusedWindow() -- hotkey.bind(f19, "1", function()
moveto(win, 2) -- local win = window.focusedWindow()
end) -- moveto(win, 1)
-- end)
hotkey.bind(hyperShift, "3", function() -- hotkey.bind(f19, "2", function()
local win = window.focusedWindow() -- local win = window.focusedWindow()
moveto(win, 3) -- moveto(win, 2)
end) -- end)
-- hotkey.bind(f19, "3", function()
-- local win = window.focusedWindow()
-- moveto(win, 3)
-- end)
-- -- move active window to previous/next monitor
-- hotkey.bind(MOFIFER_KEY_HALF, '-', function()
-- window.focusedWindow():moveOneScreenWest():maximize()
-- end)
-- hotkey.bind(MOFIFER_KEY_HALF, '=', function()
-- window.focusedWindow():moveOneScreenEast():maximize()
-- end)

0
timesync/timesync.sh Executable file → Normal file
View File