TL;DR

  • Install ddcctl
  • Set brightness from the shell: ddcctl -d 1 -b 50
  • Optionally integrate with Alfred or similar for hotkeys

Background

I have a Dell monitor which I am very, very happy with.

However, I quicky became annoyed that I was unable to control its brightness from my keyboard. This was supported out of the box for the (now discontinued) Apple monitors, and it is a feature I have come to rely on heavily over the years.

For some reason, even though modern monitors support this kind of control through the DDC protocols, it seems like Apple doesn’t want to support them. Which is a shame, because the on-screen menus of most monitors require lots of navigation to even find the brightness control. Not very convenient if you need to adjust it multiple times per day.

ddcctl

Fortunately, this is something we can easily fix with the help of a small open source tool called ddcctl.

The process is quite simple:

git clone git@github.com:kfix/ddcctl.git
cd ddcctl
make; make install

You should now have the tool installed as /usr/local/bin/ddcctl.

First, to identify the monitor you want to control, run ddcctl with no options and notice the first output. You will see something like this:

D: NSScreen #722469842 (2560x1440) DPI is 109.00
D: NSScreen #69731584 (1280x800 HiDPI)
D: NSScreen #69486251 (2560x1440) DPI is 109.00

These are the detected monitors, and in future ddcctl invocations you will refer to them as number 1, 2 or 3. This is specified with the -d option.

Let’s control monitor number 1 as an example:

  • Increase brightness: ddcctl -d 1 -b 10+
  • Decrease brightness: ddcctl -d 1 -b 10-
  • Set brightness to “50”: ddcctl -d 1 -b 50
  • Query current brightness: ddcctl -d 1 -b \?

Invoke ddcctl -h for an overview of all supported options. You can control much more than just the brightness if you need to.

Note: You will not be able to control a built-in laptop screen with this tool.

If you just want to be able to control your monitor from the command line, you’re done. However, if you want keyboard shortcuts, read on.

Alfred integration

I use Alfred 3 constantly, and its workflow feature is perfect for a task like this. Note that creating workflows requires a Powerpack license (highly recommended in any case).

Open the preferences by pressing Cmd-, with the launcher visible.

Then, on the Workflows pane:

  • Right-click on the gray canvas and select Triggers -> Hotkey
  • Press the hotkey you want to use to increase brightness
  • Right click the “Hotkey” input field and choose Trigger behaviour -> Pass through modifier keys
  • Click Save
  • Right-click on the gray canvas again and select Actions -> Run Script
  • Enter the script /usr/local/bin/ddcctl -d 1 -b 10+
  • Click Save
  • Connect the objects with a line from the hotkey to the action

Repeat the process to define a worflow that decreases the brightness, but use a new hotkey and this script instead: /usr/local/bin/ddcctl -d 1 -b 10+

You should end up with this:

Workflows

Now you will be able to control the brightness of your monitor from anywhere within OSX.

Emacs integration

Finally, if you live your life in Emacs, the easiest keyboard integration is probably to define a few elisp functions:

(defun jpt-monitor-brightness-up (monitor-id)
  (async-shell-command
    (concat "ddcctl -d " (number-to-string monitor-id) " -b 10+")))

(defun jpt-monitor-brightness-down (monitor-id)
  (async-shell-command
    (concat "ddcctl -d " (number-to-string monitor-id) " -b 10-")))

I realize that this probably not idiomatic elisp code…to the extent that such a concept actually exists.

These functions can then easily be bound to hotkeys with global-set-key.