|
hyperKey = '`' |
|
hyperKey2 = '\\' |
|
hs.loadSpoon("ReloadConfiguration") |
|
spoon.ReloadConfiguration:start() |
|
|
|
mouseCircle = nil |
|
mouseCircleTimer = nil |
|
|
|
function mouseHighlight() |
|
-- Delete an existing highlight if it exists |
|
if mouseCircle then |
|
mouseCircle:delete() |
|
if mouseCircleTimer then |
|
mouseCircleTimer:stop() |
|
end |
|
end |
|
-- Get the current co-ordinates of the mouse pointer |
|
mousepoint = hs.mouse.getAbsolutePosition() |
|
-- Prepare a big red circle around the mouse pointer |
|
mouseCircle = hs.drawing.circle(hs.geometry.rect(mousepoint.x-400, mousepoint.y-400, 800, 800)) |
|
mouseCircle:setStrokeColor({["red"]=1,["blue"]=0,["green"]=0,["alpha"]=1}) |
|
mouseCircle:setFill(false) |
|
mouseCircle:setStrokeWidth(5) |
|
mouseCircle:show() |
|
|
|
-- Set a timer to delete the circle after 3 seconds |
|
mouseCircleTimer = hs.timer.doAfter(3, function() mouseCircle:delete() end) |
|
end |
|
hs.hotkey.bind({"cmd","alt","shift"}, "D", mouseHighlight) |
|
|
|
hs.hotkey.bind({"cmd","alt"}, "up", 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 / 2 |
|
win:setFrame(f, 0) |
|
end) |
|
|
|
hs.hotkey.bind({"cmd","alt"}, "down", 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 + max.h / 2 |
|
f.w = max.w |
|
f.h = max.h / 2 |
|
win:setFrame(f, 0) |
|
end) |
|
|
|
hs.hotkey.bind({"cmd","alt"}, "left", 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 / 2 |
|
f.h = max.h |
|
win:setFrame(f, 0) |
|
end) |
|
|
|
hs.hotkey.bind({"cmd","alt"}, "right", function() |
|
local win = hs.window.focusedWindow() |
|
local f = win:frame() |
|
local screen = win:screen() |
|
local max = screen:frame() |
|
f.x = max.x + max.w / 2 |
|
f.y = max.y |
|
f.w = max.w / 2 |
|
f.h = max.h |
|
win:setFrame(f, 0) |
|
end) |
|
|
|
hs.hotkey.bind({"ctrl","alt"}, "up", function() |
|
local win = hs.window.focusedWindow() |
|
local f = win:frame() |
|
local screen = win:screen() |
|
local max = screen:frame() |
|
f.y = f.y - 100 |
|
win:setFrame(f, 0) |
|
end) |
|
|
|
hs.hotkey.bind({"ctrl","alt"}, "down", function() |
|
local win = hs.window.focusedWindow() |
|
local f = win:frame() |
|
local screen = win:screen() |
|
local max = screen:frame() |
|
f.y = f.y + 100 |
|
win:setFrame(f, 0) |
|
end) |
|
|
|
hs.hotkey.bind({"ctrl","alt"}, "left", function() |
|
local win = hs.window.focusedWindow() |
|
local f = win:frame() |
|
local screen = win:screen() |
|
local max = screen:frame() |
|
f.x = f.x - 100 |
|
win:setFrame(f, 0) |
|
end) |
|
|
|
hs.hotkey.bind({"ctrl","alt"}, "right", function() |
|
local win = hs.window.focusedWindow() |
|
local f = win:frame() |
|
local screen = win:screen() |
|
local max = screen:frame() |
|
f.x = f.x + 100 |
|
win:setFrame(f, 0) |
|
end) |
|
|
|
-- A global variable for the Hyper Mode |
|
hyper = hs.hotkey.modal.new({}, 'F17') |
|
|
|
-- Enter Hyper Mode when F18 (Hyper/Capslock) is pressed |
|
function enterHyperMode() |
|
hyper.triggered = false |
|
hyper:enter() |
|
end |
|
|
|
function exitHyperMode() |
|
hyper:exit() |
|
if not hyper.triggered then |
|
hs.eventtap.keyStroke({}, hyperKey) |
|
end |
|
end |
|
|
|
function exitHyperMode2() |
|
hyper:exit() |
|
if not hyper.triggered then |
|
hs.eventtap.keyStroke({}, hyperKey2) |
|
end |
|
end |
|
|
|
-- Bind the Hyper key |
|
f18 = hs.hotkey.bind({}, 'F18', enterHyperMode, exitHyperMode) |
|
f19 = hs.hotkey.bind({}, 'F19', enterHyperMode, exitHyperMode2) |
|
|
|
-- set up your windowfilter |
|
switcher = hs.window.switcher.new() -- default windowfilter: only visible windows, all Spaces |
|
switcher.ui.highlightColor = {0.4,0.4,0.5,0.8} |
|
switcher.ui.thumbnailSize = 112 |
|
switcher.ui.showTitles = false |
|
switcher.ui.showThumbnails = false |
|
switcher.ui.showSelectedThumbnail = false |
|
switcher.ui.showSelectedTitle = false |
|
switcher.ui.selectedThumbnailSize = 284 |
|
switcher.ui.backgroundColor = {0.3, 0.3, 0.3, 0.5} |
|
switcher.ui.fontName = 'System' |
|
switcher.ui.textSize = 14 |
|
|
|
-- bind to hotkeys; WARNING: at least one modifier key is required! |
|
hs.window.animationDuration = 0 |
|
-- hs.hotkey.bind("cmd","F18",function()switcher:next()end) |
|
hs.hotkey.bind("cmd","F18",function()hs.eventtap.keyStroke({"cmd"},hyperKey)end) |
|
hs.hotkey.bind("shift","F18",function()hs.eventtap.keyStroke("shift",hyperKey)end) |
|
hs.hotkey.bind("ctrl","F18",function()hs.eventtap.keyStroke("ctrl",hyperKey)end) |
|
hs.hotkey.bind("alt","F18",function()hs.eventtap.keyStroke("alt",hyperKey)end) |
|
-- hs.hotkey.bind("cmd-shift","F18",function()switcher:previous()end) |
|
hs.hotkey.bind("cmd-shift","F18",function()hs.eventtap.keyStroke("cmd-shift",hyperKey)end) |
|
hs.hotkey.bind("ctrl-shift","F18",function()hs.eventtap.keyStroke("ctrl-shift",hyperKey)end) |
|
hs.hotkey.bind("alt-shift","F18",function()hs.eventtap.keyStroke("alt-shift",hyperKey)end) |
|
|
|
hs.hotkey.bind("cmd","F19",function()hs.eventtap.keyStroke({"cmd"},hyperKey2)end) |
|
hs.hotkey.bind("shift","F19",function()hs.eventtap.keyStroke("shift",hyperKey2)end) |
|
hs.hotkey.bind("ctrl","F19",function()hs.eventtap.keyStroke("ctrl",hyperKey2)end) |
|
hs.hotkey.bind("alt","F19",function()hs.eventtap.keyStroke("alt",hyperKey2)end) |
|
hs.hotkey.bind("cmd-shift","F19",function()hs.eventtap.keyStroke("cmd-shift",hyperKey2)end) |
|
hs.hotkey.bind("ctrl-shift","F19",function()hs.eventtap.keyStroke("ctrl-shift",hyperKey2)end) |
|
hs.hotkey.bind("alt-shift","F19",function()hs.eventtap.keyStroke("alt-shift",hyperKey2)end) |
|
|
|
hyper:bind({},'a',function() hyper.triggered = true hs.application.launchOrFocus('Android Studio') end) |
|
hyper:bind({},'b',function() hyper.triggered = true hs.alert.show('Bundle?') end) |
|
hyper:bind({},'c',function() hyper.triggered = true hs.application.launchOrFocus('Google Chrome') end) |
|
hyper:bind({},'d',function() hyper.triggered = true hs.execute('open ~/Downloads') end) |
|
hyper:bind({},'e',function() hyper.triggered = true hs.application.launchOrFocus('Finder') end) |
|
hyper:bind({},'f',function() hyper.triggered = true hs.application.launchOrFocusByBundleID('org.mozilla.firefox') end) |
|
hyper:bind({},'g',function() hyper.triggered = true hs.application.launchOrFocus('GoodNotes 5') end) |
|
hyper:bind({},'h',function() hyper.triggered = true hs.application.launchOrFocusByBundleID('org.hammerspoon.Hammerspoon') end) |
|
hyper:bind({},'i',function() hyper.triggered = true hs.application.launchOrFocusByBundleID('com.jetbrains.intellij.ce') end) |
|
hyper:bind({},'j',function() hyper.triggered = true hs.application.launchOrFocus('Simulator') end) |
|
hyper:bind({},'k',function() hyper.triggered = true hs.application.get('qemu-system-x86_64'):activate() end) |
|
hyper:bind({},'l',function() hyper.triggered = true hs.application.launchOrFocus('iTerm') end) |
|
hyper:bind({},'m',function() hyper.triggered = true mouseHighlight() end) |
|
hyper:bind({},'n',function() hyper.triggered = true hs.application.launchOrFocus('Notion') end) |
|
hyper:bind({},'o',function() hyper.triggered = true hs.alert.show('Open Most Recent Downloaded?') end) |
|
hyper:bind({},'p',function() hyper.triggered = true hs.application.launchOrFocusByBundleID('com.apple.systempreferences') end) |
|
hyper:bind({},'q',function() hyper.triggered = true hs.application.launchOrFocus('Quip') end) |
|
hyper:bind({},'r',function() hyper.triggered = true hs.alert.show('Run?') end) |
|
hyper:bind({},'s',function() hyper.triggered = true hs.application.launchOrFocus('Slack') end) |
|
hyper:bind({},'t',function() hyper.triggered = true hs.application.launchOrFocusByBundleID('com.apple.SafariTechnologyPreview') end) |
|
hyper:bind({},'u',function() hyper.triggered = true |
|
hs.application.launchOrFocus('YouTube') |
|
-- hs.osascript.javascript([[ |
|
-- // below is javascript code |
|
-- var chrome = Application('Google Chrome'); |
|
-- chrome.activate(); |
|
-- var wins = chrome.windows; |
|
|
|
-- // loop tabs to find a web page with a title of <name> |
|
-- function main() { |
|
-- for (var i = 0; i < wins.length; i++) { |
|
-- var win = wins.at(i); |
|
-- win.visible = false; |
|
-- var tabs = win.tabs; |
|
-- for (var j = 0; j < tabs.length; j++) { |
|
-- var tab = tabs.at(j); |
|
-- tab.title(); j; |
|
-- if (tab.title().indexOf(']] .. 'YouTube' .. [[') > -1) { |
|
-- win.activeTabIndex = j + 1; |
|
-- win.visible = true; |
|
-- return; |
|
-- } |
|
-- } |
|
-- } |
|
-- } |
|
-- main(); |
|
-- // end of javascript |
|
-- ]]) |
|
end) |
|
hyper:bind({},'v',function() hyper.triggered = true hs.application.launchOrFocus('MacVim') end) |
|
hyper:bind({},'w',function() hyper.triggered = true hs.application.launchOrFocus('WhatsApp') end) |
|
-- hyper:bind({},'w',function() hyper.triggered = true |
|
-- hs.osascript.javascript([[ |
|
-- // below is javascript code |
|
-- var chrome = Application('Google Chrome'); |
|
-- chrome.activate(); |
|
-- var wins = chrome.windows; |
|
|
|
-- // loop tabs to find a web page with a title of <name> |
|
-- function main() { |
|
-- for (var i = 0; i < wins.length; i++) { |
|
-- var win = wins.at(i); |
|
-- win.visible = false; |
|
-- var tabs = win.tabs; |
|
-- for (var j = 0; j < tabs.length; j++) { |
|
-- var tab = tabs.at(j); |
|
-- tab.title(); j; |
|
-- if (tab.title().indexOf(']] .. 'WhatsApp' .. [[') > -1 || tab.title().indexOf(']] .. 'YouTube' .. [[') > -1) { |
|
-- win.activeTabIndex = j + 1; |
|
-- win.visible = true; |
|
-- return; |
|
-- } |
|
-- } |
|
-- } |
|
-- } |
|
-- main(); |
|
-- // end of javascript |
|
-- ]]) |
|
-- end) |
|
hyper:bind({},'x',function() hyper.triggered = true hs.application.launchOrFocus('Xcode') end) |
|
hyper:bind({},'y',function() hyper.triggered = true hs.eventtap.keyStroke("cmd-ctrl","v") end) |
|
hyper:bind({},'z',function() hyper.triggered = true hs.caffeinate.systemSleep() end) |
|
|
|
hyper:bind({},'up',function() |
|
hyper.triggered = true |
|
hs.osascript.applescript([[ |
|
tell application "System Events" |
|
tell process "NotificationCenter" |
|
set numwins to (count windows) |
|
repeat with i from numwins to 1 by -1 |
|
click button "Close" of window i |
|
end repeat |
|
end tell |
|
end tell |
|
]]) |
|
end) |
|
|
|
hyper:bind({},'down',function() |
|
hyper.triggered = true |
|
hs.osascript.applescript([[ |
|
tell application "System Events" |
|
tell process "NotificationCenter" |
|
set numwins to (count windows) |
|
repeat with i from 1 to numwins by 1 |
|
click button "Close" of window i |
|
end repeat |
|
end tell |
|
end tell |
|
]]) |
|
end) |
|
|
|
hyper:bind({},'left',function() |
|
hyper.triggered = true |
|
local win = hs.window.focusedWindow() |
|
local f = win:frame() |
|
local current = win:screen() |
|
local orig = current:frame() |
|
local screen = current:toWest() |
|
local target = screen:frame() |
|
f.x = f.x - orig.x + target.x |
|
f.y = f.y - orig.y + target.y |
|
if ( f.x + f.w > target.w ) |
|
then f.x = target.w - f.w |
|
end |
|
if ( f.y + f.h > target.h ) |
|
then f.y = target.h - f.h |
|
end |
|
win:setFrame(f, 0) |
|
end) |
|
|
|
hyper:bind({},'right',function() |
|
hyper.triggered = true |
|
local win = hs.window.focusedWindow() |
|
local f = win:frame() |
|
local current = win:screen() |
|
local orig = current:frame() |
|
local screen = current:toEast() |
|
local target = screen:frame() |
|
f.x = f.x - orig.x + target.x |
|
f.y = f.y - orig.y + target.y |
|
if ( f.x + f.w > target.w ) |
|
then f.x = target.w - f.w |
|
end |
|
if ( f.y + f.h > target.h ) |
|
then f.y = target.h - f.h |
|
end |
|
win:setFrame(f, 0) |
|
end) |
|
|
|
|
|
hyper:bind({},'tab',function() hyper.triggered = true mouseHighlight() end) |