Skip to content

Instantly share code, notes, and snippets.

@mendelgusmao
Created May 5, 2016 19:48
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 mendelgusmao/d50e004683d7bc84182eb29f54bc1d7c to your computer and use it in GitHub Desktop.
Save mendelgusmao/d50e004683d7bc84182eb29f54bc1d7c to your computer and use it in GitHub Desktop.
minSpeed=1500
maxSpeed=5500
highTemp=70
normalTemp=40
output=/sys/devices/platform/applesmc.768/fan1_output
manual=/sys/devices/platform/applesmc.768/fan1_manual
currentSpeed=$(cat $output)
[ "$1" = "" ] && echo $currentSpeed && exit 0
if [ "$1" = "auto" ]; then
currentTemp=$(sensors | awk -F'[^0-9]*' '/Core/{sum = sum + $3; total = total + 1}END{OFMT = "%.0f"; print sum / total}')
newSpeed=$(echo "$minSpeed + (($maxSpeed - $minSpeed) / ($highTemp - $normalTemp) * ($currentTemp - $normalTemp))" | bc | cut -d. -$
if [ $newSpeed -eq $currentSpeed ]; then
exit 0
fi
else
newSpeed=$1
fi
bash -c "echo 1 > $manual"
bash -c "echo $newSpeed > $output"
#sudo bash -c "echo 0 > $manual"
echo "$currentSpeed > $(cat $output) @ $currentTemp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment