入门
官方入门文档:https://www.hammerspoon.org
github地址:https://github.com/Hammerspoon
插件
官方插件下载:https://www.hammerspoon.org/Spoons
完整配置仓库地址
完整的配置已上传到码云公开
https://gitee.com/Cai_Programmer/hammerspoon-config.git
窗口管理配置
快捷键截图来自 Rectangle,为了延续 Rectangle 的操作习惯,我使用 hammerspoon 配置的窗口管理快捷键与 Rectangle 保持一致
hammerspoon窗口管理配置lua脚本:
local window = require "hs.window"local hotkey = require "hs.hotkey"local layout = require "hs.layout"local fnutils = require "hs.fnutils"local mouse = require "hs.mouse"local geometry = require "hs.geometry"local screen = require "hs.screen"local hyperCtrlAlt = {"control", "option"}local hyperCtrlAltAltCmd = {"control", "option", "command"}-- 设置窗口动画时长,默认是0.2window.animationDuration = 0-- 窗口移动到左1/2hotkey.bind(hyperCtrlAlt, "Left", function()window.focusedWindow():moveToUnit(layout.left50)end)-- 窗口移动到右1/2hotkey.bind(hyperCtrlAlt, "Right", function()window.focusedWindow():moveToUnit(layout.right50)end)-- 窗口移动到上1/2hotkey.bind(hyperCtrlAlt, "Up", function()window.focusedWindow():moveToUnit'[0,0,100,50]'end)-- 窗口移动到下1/2hotkey.bind(hyperCtrlAlt, "Down", function()window.focusedWindow():moveToUnit'[0,50,100,100]'end)-- 窗口移动到左上1/2hotkey.bind(hyperCtrlAlt, "U", function()window.focusedWindow():moveToUnit'[0,0,50,50]'end)-- 窗口移动到左下1/2hotkey.bind(hyperCtrlAlt, "K", function()window.focusedWindow():moveToUnit'[50,50,100,100]'end)-- 窗口移动到右上1/2hotkey.bind(hyperCtrlAlt, "I", function()window.focusedWindow():moveToUnit'[50,0,100,50]'end)-- 窗口移动到右下1/2hotkey.bind(hyperCtrlAlt, "J", function()window.focusedWindow():moveToUnit'[0,50,50,100]'end)-- 窗口移动到左1/3hotkey.bind(hyperCtrlAlt, "D", function()window.focusedWindow():moveToUnit'[0,0,33,100]'end)-- 窗口移动到中1/3hotkey.bind(hyperCtrlAlt, "F", function()window.focusedWindow():moveToUnit'[33,0,66,100]'end)-- 窗口移动到右1/3hotkey.bind(hyperCtrlAlt, "G", function()window.focusedWindow():moveToUnit'[66,0,100,100]'end)-- 窗口移动到左2/3hotkey.bind(hyperCtrlAlt, "E", function()window.focusedWindow():moveToUnit'[0,0,66,100]'end)-- 窗口移动到右2/3hotkey.bind(hyperCtrlAlt, "T", function()window.focusedWindow():moveToUnit'[33,0,100,100]'end)-- switch active windowhotkey.bind(hyperCtrlAltAltCmd, "H", function()window.switcher.nextWindow()end)-- 移动窗口到下一屏幕hotkey.bind(hyperCtrlAltAltCmd, "Left", function()local res = window.focusedWindow():moveOneScreenWest()if res == nil thenwindow.focusedWindow():moveOneScreenEast()endend)-- 移动窗口到上一屏幕hotkey.bind(hyperCtrlAltAltCmd, "Right", function()local res = window.focusedWindow():moveOneScreenEast()if res == nil thenwindow.focusedWindow():moveOneScreenWest()endend)
显示网络信息

扩展github地址:https://github.com/Hammerspoon/Spoons/raw/master/Spoons/SpeedMenu.spoon.zip
在入口文件引入扩展并启动:
local SpeedMenu = require "SpeedMenu/init"-- 在菜单栏显示网速SpeedMenu:init();SpeedMenu:start();
剪贴板历史

扩展github地址:https://github.com/Hammerspoon/Spoons/raw/master/Spoons/ClipboardTool.spoon.zip
在入口文件引入扩展并启动:
local ClipboardTool = require "ClipboardTool/init"-- 开始记录剪贴板历史ClipboardTool:start();-- 显示剪贴板历史hotkey.bind({"command", "shift"}, "V", function()ClipboardTool:showClipboard();end)
需要调整的配置:
--- 是否开启最大字数校验obj.max_size = true--- 单次复制最大字数obj.max_entry_size = 150--- 扫描剪贴板时间间隔,如果设置的太短会有功耗问题,如果设置的太长可能无法记录到历史obj.frequency = 0.8--- 保留历史记录的个数obj.hist_size = 20
