Setting Mac hot corners in the terminal
Tags: macos, systemsetup, terminal
Published: 2022-10-06 22:07:09

Last night I thought it would be a great idea to reset my Mac. Its not uncommon for me the do this every once and a while. I backed up my files and started the process to bring my mac to it's factory settings. Sometimes it's good to start from a clean slate.

With a fresh install of macOS I started downloading everything I use as a developer. Visual Studio Code, Docker, Xcode, iTerm2 and Homebrew just to name a few tools that were downloaded. I do all this manually and should probably automate the install and setup of what I can. I had the thought of working on just that as I was setting up my mac this time around.

I got to the point of setting my mac preferences and I started thinking of how I could set the hot corners with a bash script. Hot corners are one of the only mac preferences I truly care about. I constantly swipe to the bottom left to open launchpad to open programs. After a bit of digging I found there is a way.

I found a [blog post](https://blog.jiayu.co/2018/12/quickly-configuring-hot-corners-on-macos/) about setting hot corners in a paired programming situation. They used bash scripts to set and disable hot corners. This is exactly what I needed. Let me show you how to do it as well.

## Writing The Command

We use the defaults to write the different macOS configuration. The configuration for hot corners is found in `com.apple.dock`. You can write configuration for the hot corners by setting `wvous-*-corner`. The asterisk can be replaced with `tl` (top left), `tr` (top right), `bl` (top left), and `br`(bottom right). To set a specific option you will use an int to define the option. It will be one of the following.

```
0: No Option
2: Mission Control
3: Show application windows
4: Desktop
5: Start screen saver
6: Disable screen saver
7: Dashboard
10: Put display to sleep
11: Launchpad
12: Notification Center
13: Lock Screen
```

We can pull everything into the command to set the corner value. For example:

```
defaults write com.apple.dock wvous-tl-corner -int 5
```

This command will set the top left hot corner to the action of starting the screen saver.

## Saving The Changes

Now that we have set the preference we need to save the change. To do this we need to restart the dock. To do this you can run the following command.

```
killall Dock
```

Your desktop will go black and your dock will disappear. This is expected and will return to normal shortly after. 

## Modifiers

Now to take this one step further we can set a modifier. A modifier in the context of hot corners is before a hot corner will be activated a key must be held as you trigger the hot corner. Modifiers are set using the `wvous-*-modifier` setting. The asterisk is replaced like it is for the corner.

To set the modifier you can use one of the following.

```
0: No Modifier
131072: Shift Key
262144: Control Key
524288: Option Key
1048576: Command Key
```

For example, you could set the screen saver to start when the shift key is pressed and top left hot corner is triggered with these commands.

```
defaults write com.apple.dock wvous-tl-corner -int 5
```
```
defaults write com.apple.dock wvous-tl-modifier -int 131072
```
```
killall Dock
```

## What's Next?

I will use this till Apple decides to change things on me. One day I might just get that set up script done and you will see it in there. Until that comes to pass maybe you can find an awesome way to use this knowledge for your use case.

Let me know what you do with this in the comments below. It would me the world to me if you liked this article and if you want more articles like this give my account a follow.

### References
https://github.com/mathiasbynens/dotfiles/blob/master/.macos
https://blog.jiayu.co/2018/12/quickly-configuring-hot-corners-on-macos/