2

I wrote myself a bash script and when this script is called it changes my display brightness. Now i want to run this script when my ac-adapter is unplugged or the ac-adapter gets plugged in. Where can I add some events?

  • Duplicate of http://askubuntu.com/questions/55904/how-can-i-run-my-script-automatically-on-ac-switching, but I don't have /etc/pm/power.d in 15.10, so I guess that wouldn't work. – kos Mar 03 '16 at 11:49
  • See my answer here: http://askubuntu.com/q/739617/295286 . Your question is not strictly duplicate of that, but my answer essentially achieves the same task. – Sergiy Kolodyazhnyy Mar 03 '16 at 15:42

1 Answers1

1

i want to run this script when my ac-adapter is unplugged or the ac-adapter gets plugged in

There's a couple of ways. I've written a script specifically for that purpose , which uses on_ac_power script that comes with Ubuntu by default. This method simply uses infinite while loop to constantly poll the return of on_ac_power. Starting this script is done using Startup Applications app which launches commands when user logs into Gnome or Unity.

Another approach is via ACPI events. As shown on Arch Wiki , you can place a script into /etc/acpi folder that will perform checks for the presence of a specific AC adapter in /sys/class/backlight folder, and change a specific value in a file accordingly.

Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497