Trigger autorandr on Laptop Lid Open/Close

Photo of author

In the previous post on autorandr I mentioned how it didn’t respond to the Laptop lid open/close event. It’s a known issue, and a discussion is ongoing on Github: “Be aware of lid state“.

The latest autorandr is supposed to have a fix for it, but it didn’t work for me. I found another solution from that thread instead.

On a high level, the solution is:

  1. autorandr can detect the right configuration with lid open/close, it just can’t switch to it automatically since lid close/event is not an external display plug/unplug event.
  2. We simply need to hook into the lid open/close event and manually trigger the switch command: autorandr --change.
  3. This can be done using acpi on Linux. See the instructions below.

Executing Script on Lid Open/Close Event

Let’s create the script first. Create a file at the following location /etc/acpi/autorandr.sh with the following content:

#!/bin/bash

/usr/bin/autorandr --batch --change

Make sure you provide executable permission to the script by running sudo chmod +x autorandr.sh, or else it won’t work.

Next, we create a lid open/close event signal and hook the script with it. Create a file at the location /etc/api/events/lid-switch:

event=button/lid LID (open|close)
action=/etc/acpi/autorandr.sh

With this, closing/opening the lid should automatically trigger autorandr for setting your saved profile.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive updates in your inbox once a week.

I don’t spam! You can always unsubscribe if you don't like it.

🗞️ Don’t miss the latest posts!

Subscribe to the Weekly Newsletter

I won't spam. Promise!

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments