You can use Soundflower to direct the output audio to SoX.
Install Soundflower, then go to “System Preferences > Sound”, and set Soundflower (2ch) as both the output device and input device.
Then record 10 seconds using SoX, e.g. as suggested in this question and answer thread.
To switch to Soundflower as output/input device (and back) you can use the switchaudio-osx tool, which you can install via Homebrew.
Use the commands:
SwitchAudioSource -s 'Soundflower (2ch)' -t 'output'
SwitchAudioSource -s 'Soundflower (2ch)' -t 'input'
Using Soundflower, SoX, and switchaudio-osx together, it should be possible to write a script to do the whole process, with an argument for specifying the length of the recording.