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()
50 ---- multi-window layout
51 local laptopScreen = "Color LCD"
52 local windowLayout = {
53 {"Safari", nil, laptopScreen, hs.layout.left50, nil, nil},
54 {"Mail", nil, laptopScreen, hs.layout.right50, nil, nil},
55 {"iTunes", "iTunes", laptopScreen, hs.layout.maximized, nil, nil},
56 {"iTunes", "MiniPlayer", laptopScreen, nil, nil, hs.geometry.rect(0, -48, 400, 48)},
58 hs.layout.apply(windowLayout)
60 ---- Creating a simple menubar item
61 --caffeine = hs.menubar.new()
62 --function setCaffeineDisplay(state)
64 -- caffeine:setTitle("AWAKE")
66 -- caffeine:setTitle("SLEEPY")
70 --function caffeineClicked()
71 -- setCaffeineDisplay(hs.caffeinate.toggle("displayIdle"))
75 -- caffeine:setClickCallback(caffeineClicked)
76 -- setCaffeineDisplay(hs.caffeinate.get("displayIdle"))
79 -- Reacting to application events
80 -- wheny active the Finder applications, all of its windows
81 -- will be brought to the front of the display.
82 function applicationWatcher(appName, eventType, appObject)
83 if (eventType == hs.application.watcher.activated) then
84 if (appName == "Finder") then
85 -- Bring all Finder windows forward when one gets activated
86 appObject:selectMenuItem({"Window", "Bring All to Front"})
90 appWatcher = hs.application.watcher.new(applicationWatcher)