Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

LadyNinja

macrumors member
Aug 6, 2020
61
18
Norway
Ok great. I have now run your instructions from the previous posts and I can't seem to hear a change in the fans.. When I look in the mac fans control app it still seems to be running at 1200rpm. I rebooted the machine after running the final "launchctl load -w ~/Library/LaunchAgents/iMac.fan.control.plist' command in terminal too and still nothing. I'll attach below my "main.py" file and the iMac.fan.control.plist if you can check that they seem correct?

Is there a way I can check that the script is running correctly and doing what it's supposed to do?
in your main py, should it be this way?: Fan\ Control
its the path for FULL_PATH_TO_SCRIPT
 

costica1234

macrumors regular
May 21, 2013
203
150
in your main py, should it be this way?: Fan\ Control
its the path for FULL_PATH_TO_SCRIPT
I spent a long time debugging with @harrywood2 and his problem was exactly in "Fan\ Control". Removing the backslash solved the issue for him (this is because anything within <string> and </string> is a pure string and doesn't require escaping the space character).
 

franzb

macrumors newbie
Jul 29, 2021
2
2
I have come accross this solution for slowing down the iMac's fan, thanks a lot to @Andrey84 and @costica1234 for their work. Since some mentioned issues regarding "Error: SMCWriteKey() = ...", the procedure below solved this issue for me.

First, enable 'smc' to be run as root without the need to enter a password. To achieve this, create a file in /etc/sudoers.d/, e.g., with your username. In my case I've done it this way:

Code:
sudo vim /etc/sudoers.d/franz

Content of the file (obviously, you have to substitute 'franz' with your username):
Code:
franz ALL=(ALL) NOPASSWD: /Applications/smcFanControl.app/Contents/Resources/smc

For the 2017 and 2019 iMac use Automator and make it run a shell script as described by @Andrey84, adding a line to start Macs Fan Control (this way we ensure it's started after having run the smc-command, otherwise the minimum fan speed won't be applied). For me adding the first of the three lines provided was sufficient, so the lines I added to my Automator-script were these:

Code:
sudo /Applications/smcFanControl.app/Contents/Resources/smc -k F0Mn -w 0fa0
/Applications/Macs\ Fan\ Control.app/Contents/MacOS/Macs\ Fan\ Control /minimized > /dev/null 2>&1 &

For the 2020 iMac: to have the Perl script by @costica1234 run smc as root, add 'sudo' to line 33:

Code:
my @args = ("sudo", PATH_TO_SMC, "-k", $key, "-w", $value);


Update:
On my 2020 iMac, the fan resets itself to 1200 RPM after hibernation, and I've tried in vain to tweak iMac.fan.control.plist to work around this problem. So far the solution I've come up with is using DssW Power Manager (mighty tool that is complete overkill for this simple task...) to have the following script run upon wake:

Code:
launchctl unload -w /Users/franz/Library/LaunchAgents/iMac.fan.control.plist
launchctl load -w /Users/franz/Library/LaunchAgents/iMac.fan.control.plist

Maybe somebody has a simpler solution.


Update 2:
SleepWatcher can also be used (instead of DssW Power Manager). It's a little finicky to set up, but it seems to work reliably.
 
Last edited:
  • Like
Reactions: mj_ and costica1234

costica1234

macrumors regular
May 21, 2013
203
150
Thanks for your appreciation, @franzb! :)

I've been running the Perl implementation of my program for almost half a year, and it works very well on my 2020 iMac. I didn't have to use the "sudo" command you mentioned, so maybe there are some permissions-related things happening on your machine. But if you managed to get it working with "sudo", that's great!

And yes, there is this slight annoying issue that the iMac will reset to the default settings when coming back from sleep. There is a way to get around this issue by removing the conditional on line 79 of my script. However, I wouldn't recommend doing that because then the set_fan_speed function call will be executed unnecessarily in case the iMac is already in the "silent" mode and needs to stay that way for a while. There are tools like SleepWatcher to reliably solve this problem, but what I did was to just create a simple alias in my shell to quickly re-enable the script after the sleep period.
 

franzb

macrumors newbie
Jul 29, 2021
2
2
Thanks for your appreciation, @franzb! :)

I've been running the Perl implementation of my program for almost half a year, and it works very well on my 2020 iMac. I didn't have to use the "sudo" command you mentioned, so maybe there are some permissions-related things happening on your machine. But if you managed to get it working with "sudo", that's great!

And yes, there is this slight annoying issue that the iMac will reset to the default settings when coming back from sleep. There is a way to get around this issue by removing the conditional on line 79 of my script. However, I wouldn't recommend doing that because then the set_fan_speed function call will be executed unnecessarily in case the iMac is already in the "silent" mode and needs to stay that way for a while. There are tools like SleepWatcher to reliably solve this problem, but what I did was to just create a simple alias in my shell to quickly re-enable the script after the sleep period.

@costica1234, thank you for your feedback. Like stated by others before, it makes quite a difference to have the default fan speed set to 1000 RPM rather than 1200. I've had this 'fan-speed-reduction' in place now for a couple of weeks on a 2017, a 2019, and a 2020 iMac, and it has been working reliably on each one of them.

You've mentioned that on your machine the 'smc' command to set the fan speed works without root privileges. On each of my three different iMacs, 'smc' does need root, each time tested on a freshly installed macOS (11.5.1). Would be interesting to know what's different on yours.
 
Last edited:

mj_

macrumors 68000
May 18, 2017
1,616
1,281
Austin, TX
I've been running the Perl implementation of my program for almost half a year, and it works very well on my 2020 iMac. I didn't have to use the "sudo" command you mentioned, so maybe there are some permissions-related things happening on your machine. But if you managed to get it working with "sudo", that's great!
I wanted to add that I, too, had to add "sudo" to your perl script. The other way would have been to create a wrapper script around it that would then be added to sudoers.d but that would ultimately do the same thing so I opted against it. Doesn't surprise me though because smc needs to be called with root permissions otherwise it will fail.

This was so much easier on my 2017 iMac....
 

mj_

macrumors 68000
May 18, 2017
1,616
1,281
Austin, TX
SleepWatcher can also be used (instead of DssW Power Manager). It's a little finicky to set up, but it seems to work reliably.
I've setup sleepwatch, and I didn't find it finicky at all.

1) Download sleepwatcher from the developer's homepage, unzip it, launch Terminal and attempt to launch it manually, at which point macOS will throw a tantrum that it cannot run this application because it is from an unidentified developer. Open System Preferences - Security and allow sleepwatcher to operate.
2) Follow the instructions in the included ReadMe.rtf file to install sleepwatcher as well as its associated launchctl plist file
3) Create a .wakeup file in your home directory that unloads and loads costica1234's Perl or Python script and make sure it's executable (chmod +x .wakeup)
4) Load the LaunchDaemon

I was able to successfully verify that it is indeed working as expected. After wakeup my fan first attempts to spin up to 1,200 rpm but stops somewhere around 1,100 rpm and slows down to 900 again.
 

LadyNinja

macrumors member
Aug 6, 2020
61
18
Norway
Trying to make this work again. Made it work before Updated now to monterery, fresh install. Does it work?
Would wery much appreciate a helping hand.

Getting:
"Load failed: 5: Input/output error
Try running `launchctl bootstrap` as root for richer errors"
and "Error: SMCWriteKey() = e00002c1"

can't figure out about adding the sudo command. The above here doesn't match what is in the GitHub at line 33. is it "sudo", or sudo, with space, should I remove something behind/after? Have tried them all I think.

When I tried sudo launchctl load -w ~/Library/LaunchAgents/iMac.fan.control.plist, I did get a step further, asking for password then "
Warning: Expecting a LaunchDaemons path since the command was ran as root. Got LaunchAgents instead.
`launchctl bootstrap` is a recommended alternative.
/Users/xx/Library/LaunchAgents/iMac.fan.control.plist: Path had bad ownership/permissions
Load failed: 122: Path had bad ownership/permissions"


EDIT
oooooh don't mind me. I tried opening the smc, what I should not do right? It prompted for my password, quit the app, and tried again. Deleted the sudo in the main.py - and it worked! Your an angel costica. Thank you!
I'll try tomorrow with the rest.
 
Last edited:
  • Love
Reactions: costica1234
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.