Skip to content

Instantly share code, notes, and snippets.

@nwjlyons
Last active July 13, 2023 10:05
Show Gist options
  • Save nwjlyons/fdb269f8f9cb40798e83 to your computer and use it in GitHub Desktop.
Save nwjlyons/fdb269f8f9cb40798e83 to your computer and use it in GitHub Desktop.
Manually control Mac Book Pro laptop fan from linux
# First su in as root
sudo su
# Then set fan control to manual mode
echo 1 > /sys/devices/platform/applesmc.768/fan1_manual
# Then set the fan speed to any value between fan1_min and fan1_max. To view these values
cat /sys/devices/platform/applesmc.768/fan1_min
cat /sys/devices/platform/applesmc.768/fan1_max
# Set the fan speed by writing to fan1_output
echo 6200 > /sys/devices/platform/applesmc.768/fan1_output
(6200 is my max fan speed)
@gmrandazzo
Copy link

Hi,

Thank you for sharing this code. Really helpfull to me.
Can I suggest couple of modifications? :)

#!/usr/bin/env bash

if [ "$(id -u)" != "0" ]; then
   echo "Please run $0 as root" 1>&2
   exit 1
fi

if [ $# -ne 1 ]
then
    echo "Usage:"
    echo "    $0 [fan speed value] : Set Macbook pro fan speed to manual speed "
    echo "    $0 reset             : Reset Macbook pro fan speed to kernel regulation"
else
    case $1 in
        reset)
            echo "Set to automatic fan speed scaling"
            echo 0 > /sys/devices/platform/applesmc.768/fan1_manual 
        ;;
        *)
        # check if fan is set to manual
        fan_mode=`cat /sys/devices/platform/applesmc.768/fan1_manual | xargs expr`
        if [ ${fan_mode} -eq 0 ]
        then
            # Then set fan control to manual mode
            echo 1 > /sys/devices/platform/applesmc.768/fan1_manual
            echo "Switch to manual fan control..."
        fi

        fan_min_speed=`cat /sys/devices/platform/applesmc.768/fan1_min | xargs expr`
        fan_max_speed=`cat /sys/devices/platform/applesmc.768/fan1_max | xargs expr`
        if [ $1 -ge $fan_min_speed ] && [ $1 -le $fan_max_speed ]
        then
            echo "Set fan speed to $1"
            # Set the fan speed by writing to fan1_output
            echo $1 > /sys/devices/platform/applesmc.768/fan1_output
        else
            echo "Fan speed not allowed. Please specify a value between $fan_min_speed and $fan_max_speed"
        fi
    ;;
    esac
fi

Best regards

@nwjlyons
Copy link
Author

nwjlyons commented Jun 9, 2020

Thanks, looks good. I haven't used Linux on my MacBook since 2015. At the time I increased/decreased the fan speed using the functions keys. I was using OpenBox back then. Here is a write up if you are interested https://gist.github.com/nwjlyons/b29ee6f7e26595f55a2a

@gmrandazzo
Copy link

Many thanks! Beautifull the openbox setup and the key bindings.

Bests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment