Hammerspoon / hammerspoon

Staggeringly powerful macOS desktop automation with Lua
http://www.hammerspoon.org
MIT License
11.83k stars 578 forks source link

hs.execute window opens in background #3593

Closed hegga closed 3 weeks ago

hegga commented 7 months ago

Hi!

First, thank you very much for an incredible piece of software!

I have a keybinding which opens the Alacritty terminal and executes a script, my problem is that often the Alacritty window opens in the background of for example the browser which has focus when I press the keybinding. Is there any way I can avoid this? This makes me having to Cmd+Tab to focus the Alacritty window.

The keybinding looks like this:

hs.hotkey.bind({ "cmd" }, "P", function()
  hs.execute("/Applications/Alacritty.app/Contents/MacOS/alacritty --command ~/bin/fuzzy_pass.sh")
end)
dreness commented 5 months ago

Try adding the following after the execute statement:

hs.application.launchOrFocus("Alacritty")