Try several commands to restart coreaudiod in build_and_install.sh.

build_and_install.sh is failing for some people because their versions
of launchctl don't support the command we were using to restart
coreaudiod. This commit adds several fallback versions of the command.
build_and_install.sh tries each until one works.

Fixes #10, #19 and #29.
This commit is contained in:
Kyle Neideck 2016-04-20 02:35:58 +10:00
parent 9900b087ba
commit 0178644417
3 changed files with 25 additions and 5 deletions

View file

@ -5,7 +5,7 @@
- Delete `Background Music.app` from `/Applications`.
- Delete `Background Music Device.driver` from `/Library/Audio/Plug-Ins/HAL`.
- Pause apps that are playing audio, if you can.
- Restart `coreaudiod`:
- Restart `coreaudiod`:<br>
<sup>(Open `/Applications/Utilities/Terminal.app` and paste the following at the prompt.)</sup>
```shell

View file

@ -44,6 +44,8 @@ CONFIGURATION=Release
# Update .gitignore if you change this.
LOG_FILE=build_and_install.log
COREAUDIOD_PLIST="/System/Library/LaunchDaemons/com.apple.audio.coreaudiod.plist"
bold_face() {
echo $(tput bold)$*$(tput sgr0)
}
@ -197,7 +199,20 @@ sudo chown -R $(whoami):admin "/Applications/Background Music.app"
echo "Restarting coreaudiod to load BGMDriver." \
| tee -a ${LOG_FILE}
sudo launchctl kill SIGTERM system/com.apple.audio.coreaudiod
# The extra or-clauses are fallback versions of the command that restarts coreaudiod. Apparently
# some of these commands don't work with older versions of launchctl, so I figure there's no harm in
# trying a bunch of different ways (which should all work).
(sudo launchctl kill SIGTERM system/com.apple.audio.coreaudiod &>/dev/null || \
sudo launchctl kill TERM system/com.apple.audio.coreaudiod &>/dev/null || \
sudo launchctl kill 15 system/com.apple.audio.coreaudiod &>/dev/null || \
sudo launchctl kill -15 system/com.apple.audio.coreaudiod &>/dev/null || \
(sudo launchctl unload "${COREAUDIOD_PLIST}" &>/dev/null && \
sudo launchctl load "${COREAUDIOD_PLIST}" &>/dev/null) || \
sudo killall coreaudiod &>/dev/null) && \
sleep 1
# Invalidate sudo ticket
sudo -k
# Open BGMApp.
# I'd rather not open BGMApp here, or at least ask first, but you have to change your default audio

View file

@ -42,6 +42,8 @@ bgmapp_process_name="Background Music"
launchd_plist_label="com.bearisdriving.BGM.XPCHelper"
launchd_plist="/Library/LaunchDaemons/${launchd_plist_label}.plist"
coreaudiod_plist="/System/Library/LaunchDaemons/com.apple.audio.coreaudiod.plist"
user_group_name="_BGMXPCHelper"
# We move files to this temp directory and then move the directory to the user's trash at the end of the script.
@ -124,11 +126,14 @@ if [ "$user_prompt" == "y" ] || [ "$user_prompt" == "Y" ]; then
echo "Restarting Core Audio."
# The extra or-clauses are fallback versions of the command that restarts coreaudiod. Apparently some of these commands
# don't work with older versions of launchctl.
# don't work with older versions of launchctl, so I figure there's no harm in trying a bunch of different ways (which
# should all work).
(sudo launchctl kill SIGTERM system/com.apple.audio.coreaudiod &>/dev/null || \
sudo launchctl kill TERM system/com.apple.audio.coreaudiod &>/dev/null || \
sudo launchctl kill 15 system/com.apple.audio.coreaudiod &>/dev/null || \
sudo launchctl kill -15 system/com.apple.audio.coreaudiod &>/dev/null || \
(sudo launchctl unload /System/Library/LaunchDaemons/com.apple.audio.coreaudiod.plist &>/dev/null && \
sudo launchctl load /System/Library/LaunchDaemons/com.apple.audio.coreaudiod.plist &>/dev/null) || \
(sudo launchctl unload "${coreaudiod_plist}" &>/dev/null && \
sudo launchctl load "${coreaudiod_plist}" &>/dev/null) || \
sudo killall coreaudiod &>/dev/null) && \
sleep 5