Skip to content

Instantly share code, notes, and snippets.

@tsujamin
Created June 29, 2015 06:57
Show Gist options
  • Save tsujamin/830ef92e70b26de6cd2b to your computer and use it in GitHub Desktop.
Save tsujamin/830ef92e70b26de6cd2b to your computer and use it in GitHub Desktop.
fan.rb
#! /usr/bin/ruby
# SMC fan control tool
# Benjamin Roberts
# Assumes `smc` is in your path (bundled with smcFanControl)
SMC_KEY="F0Mx"
SMC_FAN_MAX=6200
SMC_FAN_MAX_KEY=0x60e0
FAN_MIN=1500
def usage(ret_val)
puts "fan.rb (#{FAN_MIN}-#{SMC_FAN_MAX})"
exit ret_val
end
if ARGV.length != 1
usage 1
end
fan_speed = ARGV[0].to_i
if fan_speed > SMC_FAN_MAX or fan_speed < FAN_MIN
usage 1
end
smc_value = (SMC_FAN_MAX_KEY * fan_speed / SMC_FAN_MAX).to_s(16)
puts "setting fan to #{fan_speed}rpm (#{SMC_KEY}=>#{smc_value})"
`smc -k #{SMC_KEY} -w #{smc_value}`
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment