2 hs.hotkey.bind({"cmd", "alt", "ctrl"}, "W", function()
3 hs.notify.new({title="Hammerspoon", informativeText="Hello World"}):send()
4 -- hs.alert.show("Hello World!")
7 -- Reload configuration
8 hs.hotkey.bind({"cmd", "alt", "ctrl"}, "R", function()
11 hs.alert.show("Config loaded")
14 -- Sample - Drawing on the screen - http://www.hammerspoon.org/go/#simplereload
16 mouseCircleTimer = nil
18 function mouseHighlight()
19 -- Delete an existing highlight if it exists
22 if mouseCircleTimer then
23 mouseCircleTimer:stop()
26 -- Get the current co-ordinates of the mouse pointer
27 mousepoint = hs.mouse.getAbsolutePosition()
28 -- Prepare a big red circle around the mouse pointer
29 mouseCircle = hs.drawing.circle(hs.geometry.rect(mousepoint.x-40, mousepoint.y-40, 80, 80))
30 mouseCircle:setStrokeColor({["red"]=1,["blue"]=0,["green"]=0,["alpha"]=1})
31 mouseCircle:setFill(false)
32 mouseCircle:setStrokeWidth(5)
35 -- Set a timer to delete the circle after 3 seconds
36 mouseCircleTimer = hs.timer.doAfter(3, function() mouseCircle:delete() end)
38 hs.hotkey.bind({"cmd","alt","shift"}, "D", mouseHighlight)
42 hs.hotkey.bind({"cmd", "alt", "ctrl"}, "H", function()
43 local win = hs.window.focusedWindow()
51 -- https://andrich.blog/2016/11/20/hammerspoon-an-awesome-tool-to-automate-your-mac/
52 -- CTRL + ALT + Left - Move current window to the left half of the screen.
53 -- CTRL + ALT + Right - Move current window to the right half of the screen.
54 -- CTRL + ALT + Up - Go "fullscreen".
55 -- CTRL + ALT + Down - Center window, covering 2/3 of screen size.
58 function move_window(direction)
60 local win = hs.window.focusedWindow()
61 local app = win:application()
62 local app_name = app:name()
64 local screen = win:screen()
65 local max = screen:frame()
67 if direction == "left" then
72 elseif direction == "right" then
73 f.x = max.x + (max.w / 2)
77 elseif direction == "up" then
82 elseif direction == "down" then
84 f.y = max.y + (max.h / 2)
87 elseif direction == "max" then
92 elseif direction == "center" then
93 f.x = max.x + (max.w / 6)
94 f.y = max.y + (max.h / 6)
98 hs.alert.show("move_window(): Freaky parameter received " .. direction)
105 local hyper = {"ctrl", "alt"}
106 hs.hotkey.bind(hyper, "h", move_window("left"))
107 hs.hotkey.bind(hyper, "l", move_window("right"))
108 hs.hotkey.bind(hyper, "k", move_window("up"))
109 hs.hotkey.bind(hyper, "j", move_window("down"))
110 hs.hotkey.bind(hyper, "m", move_window("max"))
111 hs.hotkey.bind(hyper, "c", move_window("center"))
113 -- Search and dictionary
118 -- http://zzamboni.org/post/using-spoons-in-hammerspoon/
119 -- https://github.com/Hammerspoon/Spoons/raw/master/Spoons/SpoonInstall.spoon.zip
120 if hs.spoons == nil then
121 hs.spoons=require('hs.spoons')
125 hs.loadSpoon ("SpoonInstall")
126 spoon.SpoonInstall.use_syncinstall = true
127 INSTALL = spoon.SpoonInstall
129 --------------------------------------------------------------------------------
130 -- MouseCircle http://www.hammerspoon.org/Spoons/MouseCircle.html
131 INSTALL:andUse("MouseCircle",
135 color = hs.drawing.color.x11.rebeccapurple
138 show = { {"cmd", "alt", "ctrl"}, "m"}
143 --------------------------------------------------------------------------------
144 -- TextClipboardHistory
145 INSTALL:andUse("TextClipboardHistory",
148 show_in_menubar = false,
151 toggle_clipboard = { { "cmd", "shift" }, "v"}
158 --------------------------------------------------------------------------------
159 -- Seal -- http://www.hammerspoon.org/Spoons/Seal.html
160 INSTALL:andUse("Seal",
162 hotkeys = { show = { {"cmd", "ctrl", "alt"}, "space" } },
164 s:loadPlugins({"apps", "calc", "safari_bookmarks", "screencapture", "useractions"})
165 s.plugins.safari_bookmarks.always_open_with_safari = false
166 s.plugins.useractions.actions =
168 ["Hammerspoon docs webpage"] = {
169 url = "http://hammerspoon.org/docs/",
170 icon = hs.image.imageFromName(hs.image.systemImageNames.ApplicationIcon),
171 hotkey = { hyper, "h" }
173 ["Leave corpnet"] = {
175 spoon.WiFiTransitions:processTransition('foo', 'corpnet01')
177 icon = swisscom_logo,
179 ["Arrive in corpnet"] = {
181 spoon.WiFiTransitions:processTransition('corpnet01', 'foo')
183 icon = swisscom_logo,
185 ["Translate using Leo"] = {
186 url = "http://dict.leo.org/ende/index_de.html#/search=${query}",
190 ["Tell me something"] = {
192 fn = function(str) hs.alert.show(str) end,
195 s:refreshAllCommands()