1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
   |  function activateFinder()          local focusedFinder = hs.application.get("com.apple.finder"):focusedWindow()
      if (focusedFinder == nil) then                  hs.application.launchOrFocus("finder")     else                  hs.application.get("com.apple.finder"):setFrontmost(true)     end end
 
  function toggleDesktopFiles()          script = [[         n=$(ls -lO ~/Desktop | grep -v hidden | grep -v total | wc -l | xargs);         [ $n -eq '0' ] && chflags nohidden ~/Desktop/* || chflags hidden ~/Desktop/*     ]]     hs.execute(script) end
 
  function toggleDarkAnLight()     script = [[         tell application "System Events"             tell appearance preferences                 set dark mode to not dark mode             end tell         end tell     ]]     hs.osascript.applescript(script) end
 
 
 
  function openAppUsingAltAndkey(keyAppPairs)     for key, app in pairs(keyAppPairs) do                  
                   if string.sub(app, 0, 1) ~= "/" then             app = "/Applications/" .. app         end
          
          hs.hotkey.bind({"alt"}, key .. "", function()             hs.application.open(app)
                           hs.application.frontmostApplication():setFrontmost(true)         end)     end end
 
 
 
 
  function sizeFocusedWindow(mode)     return function()         local win = hs.window.focusedWindow()         local f = win:frame()         local screen = win:screen()         local max = screen:frame()
          f.x = max.x         f.y = max.y         f.w = max.w         f.h = max.h
          if mode == "Max" then
          end         if mode == "Half Left" then             f.w = max.w / 2         end         if mode == "Half Right" then             f.x = max.x + max.w / 2             f.w = max.w / 2         end
          win:setFrame(f, 0)      end end
 
  function moveFocusedWindow(mode)     return function()         local win = hs.window.focusedWindow()         local f = win:frame()         local screen = win:screen()         local max = screen:frame()
          if mode == "Edge Left" then             f.x = max.x             f.y = 0         end         if mode == "Edge Right" then             f.x = max.x + (max.w - f.w)             f.y = 0         end         if mode == "Center" then             f.x = max.x + (max.w - f.w) / 2             f.y = max.y + (max.h - f.h) * (1-0.618)             f.x = f.x > 0 and f.x or 0             f.y = f.y > 0 and f.y or 0         end
          win:setFrame(f, 0)      end end
 
  function hideFocusedWindow()     hs.application.frontmostApplication():hide() end
 
 
 
 
  function moveCursorBetweenDesktops()     local screen = hs.mouse.getCurrentScreen()     local nextScreen = screen:next()     local rect = nextScreen:fullFrame()     local center = hs.geometry.rectMidPoint(rect)
      hs.mouse.setAbsolutePosition(center)     hs.alert.show('🐶', nextScreen)      end
 
  function moveFocusedWindowBetweenDesktops()     local win = hs.window.focusedWindow()     local screen = win:screen()     win:moveToScreen(screen:next(), 0)
           if string.find(win:title(), "RDP-Windows", 1, true) then         win:setFullScreen(true)     end end
 
 
 
 
  function trim(s)     return (s:gsub("^%s*(.-)%s*$", "%1")) end
 
  function toggleBlueTooth()          hs.execute("/opt/homebrew/bin/blueutil -p toggle")
           local state = trim(hs.execute("/opt/homebrew/bin/blueutil -p"))
      if state == "1" then         hs.alert.show("蓝牙已打开")     else         hs.alert.show("蓝牙已关闭")     end end
 
 
  function watchCallback(event)          local hour = os.date("*t").hour     if event == hs.caffeinate.watcher.systemWillSleep and hour >= 18 then         hs.execute("/opt/homebrew/bin/blueutil -p 0")     end end
  watcher = hs.caffeinate.watcher.new(watchCallback) watcher:start()
 
 
 
 
  function sendKey(a)     return function()         hs.eventtap.keyStroke({}, a)     end end
 
  function nextTab()     hs.eventtap.keyStroke({"cmd", "shift"}, ']') end function prevTab()
           hs.eventtap.keyStroke({"cmd", "shift"}, '[') end
 
 
 
 
 
  function showTime()     local weekdays = {"周一", "周二", "周三", "周四", "周五", "周六", "周日"}     local weekday = tonumber(os.date("%w"))     local t = os.date(weekdays[weekday] .. "  %H 点 %M")     hs.alert.show(t) end
 
 
 
 
 
 
  local KEY_APP_PAIRS = {     A = "IntelliJ IDEA CE.app",     C = "Google Chrome.app",     D = "Dash.app",     E = "Visual Studio Code.app",     Q = "QQ.app",          S = "Safari.app",     W = "WeChat.app",     [1] = "iTerm.app",     [2] = "Notable.app",     [3] = "Typora.app",     [4] = "/System/Applications/Preview.app", } openAppUsingAltAndkey(KEY_APP_PAIRS)
  hs.hotkey.bind({"alt"},  "F", activateFinder)                    hs.hotkey.bind({"alt"},  "H", hideFocusedWindow)                 hs.hotkey.bind({"alt"},  "X", nextTab)                           hs.hotkey.bind({"alt"},  "Z", prevTab)                           hs.hotkey.bind({"alt"},  "T", toggleBlueTooth)                   hs.hotkey.bind({"cmd"},  "H", sendKey("left"))                   hs.hotkey.bind({"cmd"},  "L", sendKey("right"))                  hs.hotkey.bind({"cmd"},  "J", sendKey("down"))                   hs.hotkey.bind({"cmd"},  "K", sendKey("up"))                     hs.hotkey.bind({"cmd"},  "I", sendKey("delete"))                 hs.hotkey.bind({"ctrl"}, "H", toggleDesktopFiles)                hs.hotkey.bind({"ctrl"}, "D", toggleDarkAnLight)                 hs.hotkey.bind({"ctrl"}, "Z", moveCursorBetweenDesktops)         hs.hotkey.bind({"ctrl"}, "X", moveFocusedWindowBetweenDesktops)  hs.hotkey.bind({"ctrl"}, "T", showTime)                          hs.hotkey.bind({"cmd", "alt", "ctrl"}, "R", hs.reload)          
  hs.hotkey.bind({"alt", "ctrl", "cmd"}, "Left",   sizeFocusedWindow("Half Left"))   hs.hotkey.bind({"alt", "ctrl", "cmd"}, "Right",  sizeFocusedWindow("Half Right"))  hs.hotkey.bind({"alt", "ctrl"},        "Return", sizeFocusedWindow("Max"))         hs.hotkey.bind({"alt", "ctrl"},        "Left",   moveFocusedWindow("Edge Left"))   hs.hotkey.bind({"alt", "ctrl"},        "Right",  moveFocusedWindow("Edge Right"))  hs.hotkey.bind({"alt", "ctrl"},        "C",      moveFocusedWindow("Center"))     
 
  ctrlDoublePress = require("ctrlDoublePress") ctrlDoublePress.timeFrame = 2 ctrlDoublePress.action = function()     moveCursorBetweenDesktops() end
 
  |