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")
13 -- Reacting to application events
14 -- Move all Finder in front
15 function applicationWatcher(appName, eventType, appObject)
16 if (eventType == hs.application.watcher.activated) then
17 if (appName == "Finder") then
18 -- Bring all Finder windows forward when one gets activated
19 appObject:selectMenuItem({"Window", "Bring All to Front"})
23 appWatcher = hs.application.watcher.new(applicationWatcher)
28 ---- Sample - Drawing on the screen - http://www.hammerspoon.org/go/#simplereload
30 --mouseCircleTimer = nil
31 --function mouseHighlight()
32 -- -- Delete an existing highlight if it exists
33 -- if mouseCircle then
34 -- mouseCircle:delete()
35 -- if mouseCircleTimer then
36 -- mouseCircleTimer:stop()
39 -- -- Get the current co-ordinates of the mouse pointer
40 -- mousepoint = hs.mouse.getAbsolutePosition()
41 -- -- Prepare a big red circle around the mouse pointer
42 -- mouseCircle = hs.drawing.circle(hs.geometry.rect(mousepoint.x-40, mousepoint.y-40, 80, 80))
43 -- mouseCircle:setStrokeColor({["red"]=1,["blue"]=0,["green"]=0,["alpha"]=1})
44 -- mouseCircle:setFill(false)
45 -- mouseCircle:setStrokeWidth(5)
48 -- -- Set a timer to delete the circle after 3 seconds
49 -- mouseCircleTimer = hs.timer.doAfter(3, function() mouseCircle:delete() end)
51 --hs.hotkey.bind({"cmd","alt","shift"}, "D", mouseHighlight)
55 --hs.hotkey.bind({"cmd", "alt", "ctrl"}, "H", function()
56 -- local win = hs.window.focusedWindow()
57 -- local f = win:frame()
64 -- https://andrich.blog/2016/11/20/hammerspoon-an-awesome-tool-to-automate-your-mac/
65 -- CTRL + ALT + Left - Move current window to the left half of the screen.
66 -- CTRL + ALT + Right - Move current window to the right half of the screen.
67 -- CTRL + ALT + Up - Go "fullscreen".
68 -- CTRL + ALT + Down - Center window, covering 2/3 of screen size.
71 function move_window(direction)
73 local win = hs.window.focusedWindow()
74 local app = win:application()
75 local app_name = app:name()
77 local screen = win:screen()
78 local max = screen:frame()
80 if direction == "left" then
85 elseif direction == "right" then
86 f.x = max.x + (max.w / 2)
90 elseif direction == "up" then
95 elseif direction == "down" then
97 f.y = max.y + (max.h / 2)
100 elseif direction == "max" then
101 if f.w > (max.w * 3/4) and f.h > (max.h * 3/4) then
102 f.x = max.x + (max.w / 6)
103 f.y = max.y + (max.h / 6)
113 hs.alert.show("move_window(): Freaky parameter received " .. direction)
120 local hyper = {"ctrl", "cmd"}
121 hs.hotkey.bind(hyper, "h", move_window("left"))
122 hs.hotkey.bind(hyper, "l", move_window("right"))
123 hs.hotkey.bind(hyper, "k", move_window("up"))
124 hs.hotkey.bind(hyper, "j", move_window("down"))
125 hs.hotkey.bind(hyper, "m", move_window("max"))
127 -- Search and dictionary
132 -- http://zzamboni.org/post/using-spoons-in-hammerspoon/
133 -- https://github.com/Hammerspoon/Spoons/raw/master/Spoons/SpoonInstall.spoon.zip
134 if hs.spoons == nil then
135 hs.spoons=require('hs.spoons')
139 hs.loadSpoon ("SpoonInstall")
140 spoon.SpoonInstall.use_syncinstall = true
141 INSTALL = spoon.SpoonInstall
143 --------------------------------------------------------------------------------
144 -- MouseCircle http://www.hammerspoon.org/Spoons/MouseCircle.html
145 INSTALL:andUse("MouseCircle",
149 color = hs.drawing.color.x11.rebeccapurple
152 show = { {"cmd", "alt", "ctrl"}, "m"}
157 --------------------------------------------------------------------------------
158 -- TextClipboardHistory
159 INSTALL:andUse("TextClipboardHistory",
162 show_in_menubar = false,
165 toggle_clipboard = { { "cmd", "shift" }, "v"}
172 --------------------------------------------------------------------------------
173 -- Seal -- http://www.hammerspoon.org/Spoons/Seal.html
174 INSTALL:andUse("Seal",
176 hotkeys = { show = { {"cmd", "ctrl", "alt"}, "space" } },
178 s:loadPlugins({"apps", "calc", "safari_bookmarks", "screencapture", "useractions"})
179 s.plugins.safari_bookmarks.always_open_with_safari = false
180 s.plugins.useractions.actions =
182 ["Hammerspoon docs webpage"] = {
183 url = "http://hammerspoon.org/docs/",
184 icon = hs.image.imageFromName(hs.image.systemImageNames.ApplicationIcon),
185 -- hotkey = { hyper, "h" }
187 ["Leave corpnet"] = {
189 spoon.WiFiTransitions:processTransition('foo', 'corpnet01')
191 icon = swisscom_logo,
193 ["Arrive in corpnet"] = {
195 spoon.WiFiTransitions:processTransition('corpnet01', 'foo')
197 icon = swisscom_logo,
199 ["Translate using Leo"] = {
200 url = "http://dict.leo.org/ende/index_de.html#/search=${query}",
204 ["Tell me something"] = {
206 fn = function(str) hs.alert.show(str) end,
209 s:refreshAllCommands()