Questions tagged [hammerspoon]

This tag should be used for questions related to lua automation tool for OSX

should be used for questions related to automation tool for

Sample

Pressing ctrl+G will display a Sample Alert! notification on your screen.

hs.hotkey.bind({"cmd"}, "S", function()
  hs.alert.show("Sample Alert!")
end)

References

70 questions
11
votes
5 answers

How to move an application between monitors in Hammerspoon?

At work I have a 3 monitor setup. I would like to move the current application to a second or a third monitor with a key binding. How to do that?
paulinhorocha
  • 412
  • 4
  • 12
11
votes
1 answer

Can I separate `init.lua` to different components in Hammerspoon?

I would like to separate init.lua script used in Hammerspoon to enhance the readability and maintainance. So it looks like the following: init.lua AppWatcher.lua WiFiWatcher.lua KeyRemap.lua And then from within init.lua I would read these files…
Blaszard
  • 30,954
  • 51
  • 153
  • 233
9
votes
1 answer

Lua Hammerspoon: hs.window.focusedWindow() is nil when assigned to a variable

I use an automation software called hammerspoon on osx. When I use the following code in hammerspoon's console, win is nil: > local win = hs.window.focusedWindow() > win nil But actually the function returns some value: >…
Mert Nuhoglu
  • 9,695
  • 16
  • 79
  • 117
7
votes
1 answer

Hammerspoon: continuously send keystrokes to one application, while using others normally

Ok, so I have a script with Hammerspoon that executes key stokes for me. Simple example: hs.hotkey.bind({'cmd','alt','ctrl'}, "b", function() hs.eventtap.keyStroke({}, "Left", 200000) hs.eventtap.keyStroke({}, "Left", 200000) …
Ian
  • 85
  • 5
7
votes
1 answer

hammerspoon remap control key: sends esc when pressed alone, send control when pressed with other keys

This is a extremely useful remap in my opinion, since you almost never type control alone, why not remap it to esc? Since karabiner is gone I've been trying to restore my favourite feature using hammerspoon, I think this can be achieved but I just…
timfeirg
  • 1,426
  • 18
  • 37
7
votes
1 answer

When remapping hyper key/caps lock to F18 with Hammerspoon, is it possible to use it with modifiers

My issue is as follows: I have my caps lock remapped to F18 using Karabiner Elements, and then Hammerspoon uses F18 as a "hyper key" to perform app specific shortcuts. My current code looks like this: -- A global variable for the Hyper Mode k =…
Doug Smith
  • 29,668
  • 57
  • 204
  • 388
6
votes
3 answers

How do I add a newline to hs.eventtap.keyStrokes in Hammerspoon?

I just started using Hammerspoon. I'm trying to output multiple lines of text by pressing Cmd+Shift+l . Here is what I have tried so far : hs.hotkey.bind({"cmd", "shift"}, "l", function() hs.eventtap.keyStrokes('from sklearn import metrics') …
6
votes
3 answers

How to check if user is connected via wifi or LAN through hammerspoon

I am thinking of having a hammerspoon wifi watcher, which do a periodic check and will disable wifi if its not connected. The following script does this, function checkAndDisableWifi() hs.timer.doAfter(45, function() local current_network =…
Gopinath Shiva
  • 3,822
  • 5
  • 25
  • 48
5
votes
1 answer

How can I prevent hammerspoon hotkeys from overriding hotkeys in other applications?

I'm looking at having a certain hotkey only available in Google Chrome: hs.hotkey.bind({"cmd"}, "0", function() if hs.window.focusedWindow():application():name() == 'Google Chrome' then hs.eventtap.keyStrokes("000000000000000000") …
doplumi
  • 2,938
  • 4
  • 29
  • 45
5
votes
3 answers

Using hammerspoon and the spaces module to move window to new space

I have installed the "undocumented spaces" module from https://github.com/asmagill/hs._asm.undocumented.spaces. In particular, it provides a method moveWindowToSpace that I am trying to use to bind cmd+1 to move the the current window to space 1…
Andrew
  • 281
  • 4
  • 16
5
votes
3 answers

Binding to multiple button clicks

To bind to the 1 key I use: hs.hotkey.bind(hyper, '1' How to bind to multiple presses of 1 key? Something like: hs.hotkey.bind(hyper, '1+1' Reading the documentation, this functionality is not mentioned. By multiple presses I mean press 1 twice…
blue-sky
  • 51,962
  • 152
  • 427
  • 752
5
votes
1 answer

Call an anonymous function with a local variable as parameter

I have a function that creates an object (in this case, a Hammerspoon Notify object), and I would like to pass this object as the parameter to an anonymous function that is itself an argument to a function call. That's a very convoluted explanation,…
Mikayla
  • 73
  • 6
4
votes
1 answer

How to use the hammerspoon CLI?

I'd like to be able to run a command like hs -m foo -c bar -- baz and run some code using bar and/or baz. The hs -h help message says that baz should be available via _cli._args or _cli.args, but I can't figure out where the _cli value…
Thom Smith
  • 13,916
  • 6
  • 45
  • 91
4
votes
1 answer

Key repeats are delayed in my Hammerspoon script

I have my CAPSLOCK bound to F18 (karabiner) to act as a modifier key. I'm trying to simulate CAPSLOCK+h, j, k, l to act as VIM movement keys. Everything works but there's an issue with delay when repeating. That is, it's very slow when I press down…
axsuul
  • 7,370
  • 9
  • 54
  • 71
4
votes
1 answer

Use image library from Hammerspoon

I'd like to use a more sophisticated graphics or GUI widget library in my Hammerspoon config file, in order to get user input and do more advanced drawing on the screen than Hammerspoon allows (as far as I can tell) by default. I'm new to Lua and…
iconoclast
  • 21,213
  • 15
  • 102
  • 138
1
2 3 4 5