Skip to content

Instantly share code, notes, and snippets.

@diegodukao
Forked from nwjlyons/common.sh
Created April 8, 2016 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegodukao/097ac4aa283f721d47a2a7dd7318ae18 to your computer and use it in GitHub Desktop.
Save diegodukao/097ac4aa283f721d47a2a7dd7318ae18 to your computer and use it in GitHub Desktop.
Instructions on how to wire up your MacBook Pro function keys to control your laptop hardware in Crunchbang
#! /bin/bash
case $1 in
up)
TOTAL=`expr $CURRENT + $INCREMENT`
if [ $TOTAL -gt $MAX ]; then
exit 1
fi
echo $TOTAL > $FILE
;;
down)
TOTAL=`expr $CURRENT - $INCREMENT`
if [ $TOTAL -lt $MIN ]; then
exit 1
fi
echo $TOTAL > $FILE
;;
max)
echo $MAX > $FILE
;;
min)
echo $MIN > $FILE
;;
toggle)
if [ $CURRENT -gt $MIN ];
then
echo $MIN > $FILE
else
echo $MAX > $FILE
fi
;;
*) echo "Invalid argument. Usage: `basename $0` up|down|max|min|toggle";;
esac

#Instructions on how to wire up your MacBook Pro function keys to control your laptop hardware in Crunchbang.

The end result of following these instructions are:

  • F3/F4 adjusts screen brightness using intervals of 1. F1/F2 use intervals of 10.
  • Apple cmd key + F3/F4 sets screen brightness to min/max
  • F5/F6 adjusts keyboard brightness.
  • Apple cmd key + F5/F6 sets keyboard brightness to min/max
  • F7/F9 adjusts laptop fan speed.
  • Apple cmd key + F7/F9 sets fan speed to min/max
  • Eject button ejects disc drive

Installation

  • mkdir /opt/control-hardware
  • Download files
  • Make files executable sudo chmod +x /opt/control-hardware/*
  • Make files run as sudo without a password
    • sudo visudo
    • Add this line to sudoers file %sudo ALL=(ALL) NOPASSWD:/opt/control-hardware/*
  • Edit openbox rc.xml
    • Add this
    <!-- Laptop fan -->
    <keybind key="XF86AudioNext">
        <action name="Execute">
          <command>sudo /opt/control-hardware/laptop-fan.sh up</command>
        </action>
    </keybind>
    <keybind key="W-XF86AudioNext">
        <action name="Execute">
          <command>sudo /opt/control-hardware/laptop-fan.sh max</command>
        </action>
    </keybind>
    <keybind key="XF86AudioPrev">
        <action name="Execute">
          <command>sudo /opt/control-hardware/laptop-fan.sh down</command>
        </action>
    </keybind>
    <keybind key="W-XF86AudioPrev">
        <action name="Execute">
          <command>sudo /opt/control-hardware/laptop-fan.sh min</command>
        </action>
    </keybind>
    <!-- Keyboard backlight -->
    <keybind key="XF86KbdBrightnessUp">
        <action name="Execute">
          <command>sudo /opt/control-hardware/keyboard-backlight.sh up</command>
        </action>
    </keybind>
    <keybind key="W-XF86KbdBrightnessUp">
        <action name="Execute">
          <command>sudo /opt/control-hardware/keyboard-backlight.sh max</command>
        </action>
    </keybind>
    <keybind key="XF86KbdBrightnessDown">
        <action name="Execute">
          <command>sudo /opt/control-hardware/keyboard-backlight.sh down</command>
        </action>
    </keybind>
    <keybind key="W-XF86KbdBrightnessDown">
        <action name="Execute">
          <command>sudo /opt/control-hardware/keyboard-backlight.sh min</command>
        </action>
    </keybind>
    <!-- Screen Backlight -->
    <keybind key="XF86LaunchB">
        <action name="Execute">
          <command>sudo /opt/control-hardware/screen-brightness.sh up</command>
        </action>
    </keybind>
    <keybind key="W-XF86LaunchB">
        <action name="Execute">
          <command>sudo /opt/control-hardware/screen-brightness.sh max</command>
        </action>
    </keybind>
    <keybind key="XF86LaunchA">
        <action name="Execute">
          <command>sudo /opt/control-hardware/screen-brightness.sh down</command>
        </action>
    </keybind>
    <keybind key="W-XF86LaunchA">
        <action name="Execute">
          <command>sudo /opt/control-hardware/screen-brightness.sh min</command>
        </action>
    </keybind>
    <!-- Eject disc drive -->
    <keybind key="XF86Eject">
        <action name="Execute">
          <command>eject</command>
        </action>
    </keybind>
  • Restart openbox

##Optional display current values on your desktop using Conky.

Add this to .conkyrc

    Fan Speed: $alignr ${exec cat /sys/devices/platform/applesmc.768/fan1_output }
    Screen brightness: $alignr ${exec cat /sys/class/backlight/nv_backlight/brightness }
    Keyboard brightness: $alignr ${exec cat /sys/class/leds/smc::kbd_backlight/brightness }
    ```
#! /bin/bash
DIR="/sys/class/leds/smc::kbd_backlight"
FILE="$DIR/brightness"
MAX=$(cat $DIR/max_brightness)
MIN=0
CURRENT=$(cat $FILE)
INCREMENT=15
CWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CWD/common.sh"
#! /bin/bash
DIR="/sys/devices/platform/applesmc.768"
FILE="$DIR/fan1_output"
MAX=$(cat $DIR/fan1_max)
MIN=$(cat $DIR/fan1_min)
CURRENT=$(cat $FILE)
INCREMENT=100
# Enable manual control of fan
echo 1 > "$DIR/fan1_manual"
CWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CWD/common.sh"
#! /bin/bash
DIR="/sys/class/backlight/nv_backlight"
FILE="$DIR/brightness"
MAX=$(cat $DIR/max_brightness)
MIN=0
CURRENT=$(cat $FILE)
INCREMENT=1
CWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CWD/common.sh"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment