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 --hs.hotkey.bind({"cmd,", "alt", "ctrl"}, "l", function()
15 -- hs.eventtap.rightClick(hs.mouse.getAbsolutePosition())
18 -- Donw : For firefox vimperator
19 hs.hotkey.bind({"cmd,", "ctrl"}, "n", function()
20 hs.eventtap.keyStroke({}, 'down')
24 hs.hotkey.bind({"cmd,", "ctrl"}, "p", function()
25 hs.eventtap.keyStroke({}, 'up')
28 -- Reacting to application events
29 -- Move all Finder in front
30 function applicationWatcher(appName, eventType, appObject)
31 if (eventType == hs.application.watcher.activated) then
32 if (appName == "Finder") then
33 -- Bring all Finder windows forward when one gets activated
34 appObject:selectMenuItem({"Window", "Bring All to Front"})
38 appWatcher = hs.application.watcher.new(applicationWatcher)
43 -- https://andrich.blog/2016/11/20/hammerspoon-an-awesome-tool-to-automate-your-mac/
44 -- CTRL + ALT + Left - Move current window to the left half of the screen.
45 -- CTRL + ALT + Right - Move current window to the right half of the screen.
46 -- CTRL + ALT + Up - Go "fullscreen".
47 -- CTRL + ALT + Down - Center window, covering 2/3 of screen size.
50 function move_window(direction)
52 local win = hs.window.focusedWindow()
53 local app = win:application()
54 local app_name = app:name()
56 local screen = win:screen()
57 local max = screen:frame()
59 if direction == "left" then
64 elseif direction == "right" then
65 f.x = max.x + (max.w / 2)
69 elseif direction == "up" then
74 elseif direction == "down" then
76 f.y = max.y + (max.h / 2)
79 elseif direction == "max" then
80 if f.w > (max.w * 3/4) and f.h > (max.h * 3/4) then
81 f.x = max.x + (max.w / 6)
82 f.y = max.y + (max.h / 6)
92 hs.alert.show("move_window(): Freaky parameter received " .. direction)
99 local hyper = {"ctrl", "cmd"}
100 hs.hotkey.bind(hyper, "h", move_window("left"))
101 hs.hotkey.bind(hyper, "l", move_window("right"))
102 hs.hotkey.bind(hyper, "k", move_window("up"))
103 hs.hotkey.bind(hyper, "j", move_window("down"))
104 hs.hotkey.bind(hyper, "m", move_window("max"))
106 -- Search and dictionary
111 -- http://zzamboni.org/post/using-spoons-in-hammerspoon/
112 -- https://github.com/Hammerspoon/Spoons/raw/master/Spoons/SpoonInstall.spoon.zip
113 if hs.spoons == nil then
114 hs.spoons=require('hs.spoons')
118 hs.loadSpoon ("SpoonInstall")
119 spoon.SpoonInstall.use_syncinstall = true
120 INSTALL = spoon.SpoonInstall
122 --------------------------------------------------------------------------------
123 -- MouseCircle http://www.hammerspoon.org/Spoons/MouseCircle.html
124 INSTALL:andUse("MouseCircle",
128 color = hs.drawing.color.x11.rebeccapurple
131 show = { {"cmd", "alt", "ctrl"}, "m"}
136 --------------------------------------------------------------------------------
137 -- TextClipboardHistory
138 INSTALL:andUse("TextClipboardHistory",
141 show_in_menubar = false,
145 toggle_clipboard = { { "cmd", "shift" }, "v"}
152 --------------------------------------------------------------------------------
153 -- Seal -- http://www.hammerspoon.org/Spoons/Seal.html
154 INSTALL:andUse("Seal",
156 hotkeys = { show = { {"cmd", "ctrl", "alt"}, "space" } },
158 s:loadPlugins({"apps", "calc", "safari_bookmarks", "screencapture", "useractions"})
159 s.plugins.safari_bookmarks.always_open_with_safari = false
160 s.plugins.useractions.actions =
162 ["Hammerspoon docs webpage"] = {
163 url = "http://hammerspoon.org/docs/",
164 icon = hs.image.imageFromName(hs.image.systemImageNames.ApplicationIcon),
165 -- hotkey = { hyper, "h" }
167 ["Leave corpnet"] = {
169 spoon.WiFiTransitions:processTransition('foo', 'corpnet01')
171 icon = swisscom_logo,
173 ["Arrive in corpnet"] = {
175 spoon.WiFiTransitions:processTransition('corpnet01', 'foo')
177 icon = swisscom_logo,
179 ["Translate using Leo"] = {
180 url = "http://dict.leo.org/ende/index_de.html#/search=${query}",
184 ["Tell me something"] = {
186 fn = function(str) hs.alert.show(str) end,
189 s:refreshAllCommands()
194 --------------------------------------------------------------------------------
195 -- Focus the last used window.
196 local function focusLastFocused()
197 local wf = hs.window.filter
198 local lastFocused = wf.defaultCurrentSpace:getWindows(wf.sortByFocusedLast)
199 if #lastFocused > 0 then lastFocused[1]:focus() end
202 -- Create the chooser.
203 -- On selection, copy the emoji and type it into the focused application.
204 local chooser = hs.chooser.new(function(choice)
205 if not choice then focusLastFocused(); return end
206 hs.pasteboard.setContents(choice["chars"])
208 hs.eventtap.keyStrokes(hs.pasteboard.getContents())
211 chooser:searchSubText(true)
212 chooser:choices(choices)
216 hs.hotkey.bind({"cmd", "alt"}, "E", function() chooser:show() end)