大西ブログ

All your blog are belong to us

入力サウンドデバイスを常にMacのメニューバーに表示する

オーディオへの興味は薄い方で、オンライン会議もMacBook Proの標準マイク・スピーカーで普段生活してます。
ところが、ひょんなことでPodcastにゲスト出演することになり、それなりに良いマイクで収録に臨まねばという気持ちになり、id:chris4403さんにMV7をお借りして試用してみています。お借りしたはいいが、これまで標準マイクだけで過ごしてたので、外付けマイクが正しく使われているか気になり、MeetやZoomの設定や、システム設定でサウンドデバイスが何に設定されているか確認してしまうという忙しない状況に……

これはよくないので改善したい。たとえば、入力デバイスをメニューバーなどに常に表示しておけないか、と試してみたがわりとあっさり実現できましたので手順メモを共有します。

メニューバーのスクリーンショット

使うツールはこの2つ

switchaudio-osx

コマンドラインでサウンドデバイスの表示や選択ができるツール。
github.com

install

$ brew install switchaudio-osx

usage

$ SwitchAudioSource
Please specify audio device.
Usage: /opt/homebrew/Cellar/switchaudio-osx/1.2.2/SwitchAudioSource [-a] [-c] [-t type] [-n] -s device_name | -i device_id | -u device_uid
  -a             : shows all devices
  -c             : shows current device

  -f format      : output format (cli/human/json). Defaults to human.
  -t type        : device type (input/output/system/all).  Defaults to output.
  -m mute        : sets the mute status (mute/unmute/toggle).  For input/output only.
  -n             : cycles the audio device to the next one
  -i device_id   : sets the audio device to the given device by id
  -u device_uid  : sets the audio device to the given device by uid or a substring of the uid
  -s device_name : sets the audio device to the given device by name

ということなので、こんなコマンドで利用中のマイクデバイスを表示できます。

$ SwitchAudioSource -c -t input
Shure MV7

うむ、バッチリ。

xbar

メニューバーに何でも置けるツール。プラグインを任意のスクリプトで書けるので自由度が高い。

Put anything in your macOS menu bar

Mac のメニューバーで PR の状況を把握する - maiyama log この記事を参考にしました。

plugin


メニューバーから Open plugin folder でプラグインを格納するディレクトリを開ける。
自分の環境では、/Users/onishi/Library/Application Support/xbar/pluginsでした。ここにプラグインのスクリプトを置けば自動でロードしてくれる。
プラグインの書き方のドキュメントはこちら https://github.com/matryer/xbar-plugins/blob/main/CONTRIBUTING.md

{name}.{time}.{ext}

  • name - The name of the file
  • time - The refresh rate (see below)
  • ext - The file extension

簡単!ということで、10秒ごとにサウンドデバイスを調べるスクリプトを用意します。

sound.10s.sh

#!/usr/bin/env bash

/opt/homebrew/bin/SwitchAudioSource -c -t input

このファイルを先程のプラグインディレクトリに置く。

できました!

社のSlackの分報で「こういうことしたい」と呟いたら id:cockscomb が xbar について書かれた id:maiyama4 のブログを教えてくれたので、やりたいと思ってものの10分でできました!同僚に感謝!

はてなで一緒に働きませんか?