Can you share the Swift script? I was thinking of doing something similar but was banging my head against the audio side of macOS.