#!/bin/sh
# Make the audio system load the new driver. launchctl is the reliable way; killall is the fallback
# (on some systems killall alone does not restart coreaudiod).
chown -R root:wheel "/Library/Audio/Plug-Ins/HAL/BlackHole_Studio.driver"
before=$(pgrep -x coreaudiod)
launchctl kickstart -k system/com.apple.audio.coreaudiod 2>/dev/null
sleep 3
after=$(pgrep -x coreaudiod)
if [ -z "$after" ] || [ "$after" = "$before" ]; then
  killall coreaudiod 2>/dev/null; sleep 3; after=$(pgrep -x coreaudiod)
fi
if [ -n "$before" ] && [ "$after" = "$before" ]; then
  kill -TERM "$before" 2>/dev/null
fi
exit 0
