Last active
February 29, 2020 15:35
-
-
Save sergeybe/7a6e01ef828fb6ee4d7f67bd5fe689a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local hyper = {"cmd", "alt", "ctrl", "shift"} | |
| local applicationHotkeys = { | |
| e = 'Google Chrome', | |
| t = 'iTerm2', | |
| s = 'Slack', | |
| x = 'Xcode', | |
| v = 'VS Code', | |
| p = 'System Preferences', | |
| f = 'Firefox', | |
| } | |
| hs.window.animationDuration = 0 | |
| hs.window.setShadows(false) | |
| -- hs.alert.defaultStyle.strokeColor = {white = 1, alpha = 0} | |
| -- hs.alert.defaultStyle.fillColor = {white = 0.05, alpha = 0.75} | |
| -- hs.alert.defaultStyle.radius = 5 | |
| for key, app in pairs(applicationHotkeys) do | |
| hs.hotkey.bind(hyper, key, function() | |
| hs.application.launchOrFocus(app) | |
| end) | |
| end | |
| keyWatcher = hs.eventtap.new({hs.eventtap.event.types.flagsChanged}, function(event) | |
| local flags = event:getFlags() | |
| local keyCode = event:getKeyCode() | |
| local char = event:getCharacters() | |
| -- print('flag ', hs.inspect(keyCode)) | |
| if not char and flags.shift and flags.cmd and not (flags.ctrl or flags.fn or flags.alt) then | |
| local layout = hs.keycodes.currentLayout() | |
| if layout == 'ABC' then | |
| hs.keycodes.setLayout('Russian - PC') | |
| else | |
| hs.keycodes.setLayout('ABC') | |
| end | |
| hs.alert.show(hs.keycodes.currentLayout()) | |
| end | |
| -- print('flag', hs.inspect(keyCode)) | |
| -- print(hs.keycodes.currentSourceID()) | |
| -- com.apple.keylayout.ABC | |
| -- com.apple.keylayout.RussianWin | |
| end) | |
| keyWatcher:start() | |
| keyWatcher2 = hs.eventtap.new({hs.eventtap.event.types.keyDown}, function(event) | |
| if event:getFlags()["fn"] then | |
| if event:getCharacters() == "4" then | |
| hs.caffeinate.systemSleep() | |
| return false | |
| end | |
| end | |
| end) | |
| keyWatcher2:start() | |
| hs.hotkey.bind(hyper, "W", function() | |
| hs.alert.show("Hello World!") | |
| end) | |
| hs.hotkey.bind(hyper, "A", function() | |
| hs.alert.show("Hello AAAAAA!") | |
| end) | |
| hs.hotkey.bind(hyper, "D", function() | |
| -- spoon = hs.loadSpoon("BingDaily") | |
| -- spoon:init() | |
| end) | |
| hs.hotkey.bind(hyper, "Delete", function() | |
| hs.alert.show("Screensaver") | |
| hs.caffeinate.startScreensaver() | |
| end) | |
| hs.hotkey.bind(hyper, "0", function() | |
| hs.reload() | |
| -- hs.loadSpoon("ReloadConfiguration") | |
| -- spoon.ReloadConfiguration:start() | |
| end) | |
| hs.hotkey.bind(hyper, "h", function() | |
| local win = hs.window.focusedWindow(); | |
| if not win then | |
| return | |
| end | |
| win:moveToUnit(hs.layout.left50) | |
| end) | |
| hs.hotkey.bind(hyper, "j", function() | |
| local win = hs.window.focusedWindow(); | |
| if not win then | |
| return | |
| end | |
| win:moveToUnit(hs.layout.maximized) | |
| end) | |
| hs.hotkey.bind(hyper, "k", function() | |
| local win = hs.window.focusedWindow(); | |
| if not win then | |
| return | |
| end | |
| win:moveToScreen(win:screen():next()) | |
| end) | |
| hs.hotkey.bind(hyper, "l", function() | |
| local win = hs.window.focusedWindow(); | |
| if not win then | |
| return | |
| end | |
| win:moveToUnit(hs.layout.right50) | |
| end) | |
| hs.urlevent.bind("notify", function(event, params) | |
| hs.alert.show(params["message"]) | |
| end) | |
| -- hs.notify.new({title="Hammerspoon", informativeText="Config loaded"}):send() | |
| hs.alert.show("Config loaded") | |
| -- hs.loadSpoon("reload") | |
| -- spoon.reload:start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment