From 4da3c8eef9c7b30e83edff8894441a2231eb7ec0 Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev <48208649+miketimofeev@users.noreply.github.com> Date: Tue, 8 Jun 2021 10:44:31 +0300 Subject: [PATCH] Add blackhole audiodevice for macOS Big sur, add sox and Switchaudio-osx versions to the docs (#3542) --- .../macos/helpers/SoftwareReport.Helpers.psm1 | 11 +++++++++ images/macos/provision/core/audiodevice.sh | 23 ++++++++++++++----- .../SoftwareReport.Common.psm1 | 10 ++++++++ .../SoftwareReport.Generator.ps1 | 7 ++++++ images/macos/templates/macOS-11.json | 1 + images/macos/tests/System.Tests.ps1 | 8 +++++-- 6 files changed, 52 insertions(+), 8 deletions(-) diff --git a/images/macos/helpers/SoftwareReport.Helpers.psm1 b/images/macos/helpers/SoftwareReport.Helpers.psm1 index 6f1bac5b5..b996f64b8 100644 --- a/images/macos/helpers/SoftwareReport.Helpers.psm1 +++ b/images/macos/helpers/SoftwareReport.Helpers.psm1 @@ -49,3 +49,14 @@ function Get-PathWithLink { $link = Get-LinkTarget($inputPath) return "${inputPath}${link}" } + +function Get-BrewPackageVersion { + param ( + [string] $CommandName + ) + + (Get-LinkTarget (Get-Command $CommandName).Source | Out-String) -match "(?(\d+.){2}\d+)" | Out-Null + $packageVersion = $Matches.Version + + return $packageVersion +} \ No newline at end of file diff --git a/images/macos/provision/core/audiodevice.sh b/images/macos/provision/core/audiodevice.sh index bf9f0f322..a078c04f8 100644 --- a/images/macos/provision/core/audiodevice.sh +++ b/images/macos/provision/core/audiodevice.sh @@ -1,17 +1,28 @@ #!/bin/bash -e -o pipefail source ~/utils/utils.sh -echo "install soundflower" -brew install --cask soundflower - echo "install switchaudio-osx" brew_smart_install "switchaudio-osx" echo "install sox" brew_smart_install "sox" -echo "set Soundflower (2ch) as input/output device" -SwitchAudioSource -s "Soundflower (2ch)" -t input -SwitchAudioSource -s "Soundflower (2ch)" -t output +# Big Sur doesn't support soundflower installation without user interaction https://github.com/mattingalls/Soundflower/releases/tag/2.0b2 +# Install blackhole-2ch for Big Sur instead +if is_Less_BigSur; then + echo "install soundflower" + brew install --cask soundflower + + echo "set Soundflower (2ch) as input/output device" + SwitchAudioSource -s "Soundflower (2ch)" -t input + SwitchAudioSource -s "Soundflower (2ch)" -t output +else + echo "install blackhole-2ch" + brew_smart_install "blackhole-2ch" + + echo "set BlackHole 2ch as input/output device" + SwitchAudioSource -s "BlackHole 2ch" -t input + SwitchAudioSource -s "BlackHole 2ch" -t output +fi invoke_tests "System" "Audio Device" diff --git a/images/macos/software-report/SoftwareReport.Common.psm1 b/images/macos/software-report/SoftwareReport.Common.psm1 index 8585cd054..f94ef3865 100644 --- a/images/macos/software-report/SoftwareReport.Common.psm1 +++ b/images/macos/software-report/SoftwareReport.Common.psm1 @@ -462,6 +462,16 @@ function Get-CabalVersion { return "Cabal $cabalVersion" } +function Get-SwitchAudioOsxVersion { + $switchAudioVersion = Get-BrewPackageVersion -CommandName "SwitchAudioSource" + return "Switchaudio-osx $switchAudioVersion" +} + +function Get-SoxVersion { + $soxVersion = Get-BrewPackageVersion -CommandName "sox" + return "Sox $soxVersion" +} + function Get-StackVersion { $stackVersion = Run-Command "stack --version" | Take-Part -Part 1 | ForEach-Object {$_.replace(",","")} return "Stack $stackVersion" diff --git a/images/macos/software-report/SoftwareReport.Generator.ps1 b/images/macos/software-report/SoftwareReport.Generator.ps1 index 89f455c2f..b2eca6c39 100644 --- a/images/macos/software-report/SoftwareReport.Generator.ps1 +++ b/images/macos/software-report/SoftwareReport.Generator.ps1 @@ -145,6 +145,13 @@ if ($os.IsLessThanBigSur) { ) } +if (-not $os.IsHighSierra) { + $utilitiesList += @( + (Get-SwitchAudioOsxVersion), + (Get-SoxVersion) + ) +} + $markdown += New-MDList -Style Unordered -Lines ($utilitiesList | Sort-Object) $markdown += New-MDNewLine diff --git a/images/macos/templates/macOS-11.json b/images/macos/templates/macOS-11.json index 8db2da6b2..f8661baa1 100644 --- a/images/macos/templates/macOS-11.json +++ b/images/macos/templates/macOS-11.json @@ -182,6 +182,7 @@ "./provision/core/nginx.sh", "./provision/core/postgresql.sh", "./provision/core/mongodb.sh", + "./provision/core/audiodevice.sh", "./provision/core/vcpkg.sh", "./provision/core/miniconda.sh", "./provision/core/chrome.sh", diff --git a/images/macos/tests/System.Tests.ps1 b/images/macos/tests/System.Tests.ps1 index ea5e13755..0aa40c395 100644 --- a/images/macos/tests/System.Tests.ps1 +++ b/images/macos/tests/System.Tests.ps1 @@ -17,7 +17,7 @@ Describe "Certificate" { } } -Describe "Audio device" -Skip:($os.IsHighSierra -or $os.IsBigSur) { +Describe "Audio device" -Skip:($os.IsHighSierra) { It "Sox is installed" { "sox --version" | Should -ReturnZeroExitCode } @@ -26,9 +26,13 @@ Describe "Audio device" -Skip:($os.IsHighSierra -or $os.IsBigSur) { "SwitchAudioSource -c" | Should -ReturnZeroExitCode } - It "Audio channel Soundflower (2ch)" { + It "Audio channel Soundflower (2ch)" -Skip:($os.IsBigSur) { SwitchAudioSource -c | Should -BeLikeExactly "Soundflower (2ch)" } + + It "Audio channel BlackHole 2ch" -Skip:($os.IsLessThanBigSur) { + SwitchAudioSource -c | Should -BeLikeExactly "BlackHole 2ch" + } } Describe "Screen Resolution" -Skip:($os.IsHighSierra) {