> ## Content Index
> Fetch the complete content index at: https://hanatane.net/llms.txt
> Use this file to discover other available public pages before exploring further.

# AlfredでMacの音声を切り替える
- URL: https://hanatane.net/alfred-switchaudio-osx/
- Published: 2024-02-06T13:27:40.000Z
- Updated: 2024-02-06T13:27:40.000Z
- Description: AlfredでMacの音声を切り替えるAlfred Workflowを作った
- Author: たねのぶ
- Tags: 技術の話, #Import 2025-03-18 13:46

BeatsFitProを使ってるのですが、BluetoothイヤホンをMacで使っているときにうっかりBluetoothマイクがオンになるとレイテンシー重視のコーデックに切り替わって音質がめちゃくちゃ悪くなります。

なのでマイクを使う前にMacbookの内蔵マイクに切り替えるのですが、毎回メニューバー→Soundをoption+クリック→マイクを選択というのがとても面倒です。さらにH1の強みを活かして頻繁に接続を切り替えるので、切り替わる度にマイクが変わってしまいます。デフォルトで内蔵マイクを使うように設定できればいいのですが…。

というわけで回避策はないかと調べたら[switchaudio-osx](https://github.com/deweller/switchaudio-osx?ref=hanatane.net)というコマンドラインツールがありました。あとはこれをAlfredで実行するだけでいいじゃんということで、誰かやってないかと思ったやっぱりありました。

[GitHub - alexlafroscia/alfred-switch-audio-source: Alfred workflow to switch audio deviceAlfred workflow to switch audio device. Contribute to alexlafroscia/alfred-switch-audio-source development by creating an account on GitHub.![](https://github.githubassets.com/assets/pinned-octocat-093da3e6fa40.svg)GitHubalexlafroscia![](https://opengraph.githubassets.com/8a85c221ae047f618f11238b21371a56bf10ee540e845e3494290ead7f7828b8/alexlafroscia/alfred-switch-audio-source)](https://github.com/alexlafroscia/alfred-switch-audio-source?ref=hanatane.net)

しかしうまく動きません。どうも内部的にPython2を使っているのが原因っぽいです。workaroundもいくつかありそうでしたが、やりたいことはシンプルなので例のごとくChatGPTにApple Scriptを書いてもらって実装しました。

[GitHub - mtane0412/alfred-switch-audio-osx: Alfredでswitchaudio-osxを使うworkflowAlfredでswitchaudio-osxを使うworkflow. Contribute to mtane0412/alfred-switch-audio-osx development by creating an account on GitHub.![](https://github.githubassets.com/assets/pinned-octocat-093da3e6fa40.svg)GitHubmtane0412![](https://opengraph.githubassets.com/3da736257ddd40205cbb46c93fe0668c9878f0ad12e92c9661819b0fd1fbc9eb/mtane0412/alfred-switch-audio-osx)](https://github.com/mtane0412/alfred-switch-audio-osx?ref=hanatane.net)

![動作している様子](https://hanatane.net/content/images/2024/02/3697a11d444ba6663dad7321e1afdda3-1.gif)

個人的にめちゃくちゃ便利になりました。

Alfredは開発のしやすさでPythonとかNodeを中身で使うことがありますが、それぞれの言語のバージョンで次第に使えなくなるworkflowが多い印象です。Apple ScriptはApple謹製なのでそれらに比べると長く使えるんじゃないかなーという思うのですが、実際のところどうなんでしょうね。