ACTUALLY I think I may have a near-perfect solution. It requires a bit of setup, but should work noiselessly in the background forever after.
(Full disclosure: I haven't tested this on my Hackintosh yet. However, it's based entirely on a working setup I have for something else.) EDIT: Works exactly as expected on my Hackintosh. Machine wakes from sleep, sound doesn't work for a second or two, sound starts working again. No password input needed.
What we're going to do is turn shilohh's AppleScript code (which is just a wrapper for some BASH commands anyway) into a BASH script, then make a launch daemon that runs this script every time the machine wakes.
The script is very simple: create /Library/Scripts/HDAreload.sh (or whatever you would like to call it) with this code:
Code:
#!/bin/bash
[FONT=Verdana]kextunload /System/Library/Extensions/AppleHDA.kext
kextload /System/Library/Extensions/AppleHDA.kext
kextload /System/Library/Extensions/AppleHDA.kext # not sure why this is here twice, but that's how it was in the original. Maybe a pause is needed instead?[/FONT][FONT=Verdana]
[/FONT]exit 0
Now we need to set up the daemon. This is accomplished with a separate function, Bernhard Baehr's sleepwatcher. Download from
his website and install as described in the readme. (He wants you to install to /usr/local/sbin, but I just put it in /usr/bin like I usually do. Not sure if that's best-practice or not.) Now create the file /System/Library/LaunchDaemons/de.bernhard-baehr.sleepwatcher.plist as follows:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>de.bernhard-baehr.sleepwatcher</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/sbin/sleepwatcher</string> <!-- path to exec -->
<string>-w /Scripts/Library/HDAreload.sh</string> <!-- your script path -->
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>UserName</key>
<string>root</string> <!-- allows file to run w/o needing admin pw -->
</dict>
</plist>
Almost done—just run
Code:
sudo launchctl load -wF /System/Library/LaunchDaemons/de.bernhard-baehr.sleepwatcher.plist
in Terminal and you should be good!