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 -- https://andrich.blog/2016/11/20/hammerspoon-an-awesome-tool-to-automate-your-mac/
29 -- CTRL + ALT + Left - Move current window to the left half of the screen.
30 -- CTRL + ALT + Right - Move current window to the right half of the screen.
31 -- CTRL + ALT + Up - Go "fullscreen".
32 -- CTRL + ALT + Down - Center window, covering 2/3 of screen size.
35 function move_window(direction)
37 local win = hs.window.focusedWindow()
38 local app = win:application()
39 local app_name = app:name()
41 local screen = win:screen()
42 local max = screen:frame()
44 if direction == "left" then
49 elseif direction == "right" then
50 f.x = max.x + (max.w / 2)
54 elseif direction == "up" then
59 elseif direction == "down" then
61 f.y = max.y + (max.h / 2)
64 elseif direction == "max" then
65 if f.w > (max.w * 3/4) and f.h > (max.h * 3/4) then
66 f.x = max.x + (max.w / 6)
67 f.y = max.y + (max.h / 6)
77 hs.alert.show("move_window(): Freaky parameter received " .. direction)
84 local hyper = {"ctrl", "cmd"}
85 hs.hotkey.bind(hyper, "h", move_window("left"))
86 hs.hotkey.bind(hyper, "l", move_window("right"))
87 hs.hotkey.bind(hyper, "k", move_window("up"))
88 hs.hotkey.bind(hyper, "j", move_window("down"))
89 hs.hotkey.bind(hyper, "m", move_window("max"))
91 -- Search and dictionary
96 -- http://zzamboni.org/post/using-spoons-in-hammerspoon/
97 -- https://github.com/Hammerspoon/Spoons/raw/master/Spoons/SpoonInstall.spoon.zip
98 if hs.spoons == nil then
99 hs.spoons=require('hs.spoons')
103 hs.loadSpoon ("SpoonInstall")
104 spoon.SpoonInstall.use_syncinstall = true
105 INSTALL = spoon.SpoonInstall
107 --------------------------------------------------------------------------------
108 -- MouseCircle http://www.hammerspoon.org/Spoons/MouseCircle.html
109 INSTALL:andUse("MouseCircle",
113 color = hs.drawing.color.x11.rebeccapurple
116 show = { {"cmd", "alt", "ctrl"}, "m"}
121 --------------------------------------------------------------------------------
122 -- TextClipboardHistory
123 INSTALL:andUse("TextClipboardHistory",
126 show_in_menubar = false,
130 toggle_clipboard = { { "cmd", "shift" }, "v"}
137 --------------------------------------------------------------------------------
138 -- Seal -- http://www.hammerspoon.org/Spoons/Seal.html
139 INSTALL:andUse("Seal",
141 hotkeys = { show = { {"cmd", "ctrl", "alt"}, "space" } },
143 s:loadPlugins({"apps", "calc", "safari_bookmarks", "screencapture", "useractions"})
144 s.plugins.safari_bookmarks.always_open_with_safari = false
145 s.plugins.useractions.actions =
147 ["Hammerspoon docs webpage"] = {
148 url = "http://hammerspoon.org/docs/",
149 icon = hs.image.imageFromName(hs.image.systemImageNames.ApplicationIcon),
150 -- hotkey = { hyper, "h" }
152 ["Leave corpnet"] = {
154 spoon.WiFiTransitions:processTransition('foo', 'corpnet01')
156 icon = swisscom_logo,
158 ["Arrive in corpnet"] = {
160 spoon.WiFiTransitions:processTransition('corpnet01', 'foo')
162 icon = swisscom_logo,
164 ["Translate using Leo"] = {
165 url = "http://dict.leo.org/ende/index_de.html#/search=${query}",
169 ["Tell me something"] = {
171 fn = function(str) hs.alert.show(str) end,
174 s:refreshAllCommands()