Skip to content

Instantly share code, notes, and snippets.

@osteslag
Last active January 28, 2018 20:06
Show Gist options
  • Save osteslag/0f0495406bb00abc6485 to your computer and use it in GitHub Desktop.
Save osteslag/0f0495406bb00abc6485 to your computer and use it in GitHub Desktop.
Control the fan speed of an 27-inch, Mid 2010, iMac. I use this after installing an SSD drive instead of the factory-supplied HDD.
#!/bin/sh
version="0.1"
script=$(basename $0)
smc=/Applications/smcFanControl.app/Contents/Resources/smc
smc_key="F1Mx" # HDD fan key
minimum_speed=2500
fan_speed=0
version () {
smc_version=$($smc -v)
echo "$script version $version ($smc_version) by Joachim Bondo <joachim@bondo.net>" >&2
}
usage () {
cat << EOF >&2
Synopsis:
Fan control, using smcFanControl
Usage:
$script [options]
Options:
-s, --speed <speed> Sets fan speed (RPM)
-h, --help Shows this help text
-v, --version Shows script, app version
Notes:
- Requires the smcFanControl app to be installed.
- With no options the script outputs the current fan setting.
- Valid fan speeds are: 2500, 3000, 3600, 4000, 4800, 5000, 5600, 6200.
See:
- http://www.ifixit.com/Answers/View/14068/#answer40908
- https://github.com/hholtmann/smcFanControl
- $smc -h
EOF
}
readout () {
$smc -k $smc_key -r
}
bytes_from_speed () {
case $1 in
6200 ) echo "60e0";;
5600 ) echo "5780";;
5000 ) echo "4e20";;
4800 ) echo "4b00";;
4000 ) echo "3e80";;
3600 ) echo "3840";;
3000 ) echo "2ee0";;
2500 ) echo "2710";;
esac
}
if [ $# -eq 0 ]; then
readout
exit 0
fi
while [ $# -gt 0 ]; do
case $1 in
-h | --help )
version
echo ""
usage
exit 0
;;
-v | --version )
version
exit 0
;;
-s | --speed )
fan_speed=$2
shift
;;
* ) # Unknown option
echo "Illegal option ($1)." >&2
usage
exit 1
;;
esac
shift
done
fan_speed_bytes=$(bytes_from_speed $fan_speed)
if [ -n $fan_speed_bytes ]; then
$smc -k $smc_key -w $fan_speed_bytes
readout
else
echo "Illegal speed ($fan_speed). See help for a list of valid values." >&2
exit 1;
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment