How to open apps with keyboard shortcuts on macOS with skhd

Featured image

What I’ve always loved about Linux is its customizability and the freedom you have to configure your rice exactly you like it, especially when you pass the line of Desktop Environments to embrace more straightforward environments like tiling manager; this is where Linux on the desktop shines.

Tiling managers allow arranging windows in non-overlapping frames and controlling any aspect using the keyboard, including opening, closing, moving, and resizing.

Like the most known desktop environments (including macOS), they also have the concept of workspaces, where you can organize your windows in a way you feel more productive.

In order of preference, the things I love about this workflow:

  1. Opening a terminal with Super+Enter
  2. Opening a new browser instance with Super+Shift+Enter
  3. Move a window in another workspace with Super+Shift+[1,n]
  4. Resize the windows (well, its frame) with Super+r plus the arrows

Now, approaching to the core of this article, I use both Linux and macOS daily, and I share most of the dotfiles between the systems (i use yadm); everything works very well except the desktop workflow and the keyboard shortcuts that i cannot easily share.

Tiling window managers on macOS ? Link to heading

macOS doesn’t have a native windows tiling management (well, there is one, but very limited to full-screen apps). Some open-source projects aim to fix that, like Amethyst or Yabai; I am currently using the first one, which is quite ok for casual usage but very limited for the most advanced scenarios; in that case, consider Yabai, which requires a most complex installation to take deeper control of the operating system part in charge of window management.

Another significant missing is there isn’t a simple way on macOS to have a shortcut to spin up a new application (like a new terminal window) or a new instance of the already open program.

To do that, you must use a combination of stuff like Automator and keyboard shortcuts with many limitations on the usable keys; for example, it’s impossible to use Super+Enter as a shortcut combination.

It is frustrating but easily fixable using a small and ingenious system daemon called skhd.

What is skhd ? Link to heading

skhd is a simple hotkey daemon for macOS that focuses on responsiveness and performance. Hotkeys are defined in a text file through a simple DSL. skhd is able to hotload its config file, meaning that hotkeys can be edited and updated live while skhd is running.

How to use it? Link to heading

Once installed brew and started the launchd service:

brew install koekeishiya/formulae/skhd
brew services start skhd

You need to create a configuration file in one of the following locations (in order of preference):

- $XDG_CONFIG_HOME/skhd/skhdrc
- $HOME/.config/skhd/skhdrc
- $HOME/.skhdrc

And start adding your keyboard shortcuts, for now i have just 2:

1## Inspirations
5# Open iterm2.
6cmd - return : osascript -e 'tell application "iTerm2" to create window with default profile command ""' || open -na iTerm
8# open Chrome.
9cmd + shift - return : open -n -a "Google Chrome"

With those two lines, I’ve finally managed to have the same shortcuts for both systems and fix something I’ve always felt very clunky for years on macOS.

I hope you find this article useful, having a cozy environment is a crucial part of a good developer experience.

PS: The cover image is real working desktop based on AwesomeWM, you can find all the information here: