Last active
May 18, 2021 04:49
-
-
Save wata/0c5344055e408b6f4250ae0e877fa893 to your computer and use it in GitHub Desktop.
Connect AirPods from Terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# AlfredのWorkflowではPATHを通す処理が必要 | |
# (これをせずに直にフルパス打つ方法もあるがApple Siliconマシンとの互換性問題が生じる) | |
# Cocoapods | |
export PATH=/usr/local/bin:$PATH | |
# Cocoapods(ARM) | |
export PATH=/opt/homebrew/bin:$PATH | |
AIR_PODS_NAME=wAPP | |
# Bluetooth接続 | |
blueutil --connect $AIR_PODS_NAME | |
for ((i=0 ; i<10 ; i++)) | |
do | |
if [ "1" = $(blueutil --is-connected $AIR_PODS_NAME) ]; then | |
# 出力切替 | |
for ((j=0 ; j<10 ; j++)) | |
do | |
SwitchAudioSource -s $AIR_PODS_NAME | |
sleep 1 | |
if [ $AIR_PODS_NAME = $(SwitchAudioSource -c) ]; then | |
osascript -e ' | |
set AIR_PODS_NAME to "wAPP" | |
set Volume 1 | |
tell application "System Events" | |
tell application process "ControlCenter" | |
click menu bar item "サウンド" of menu bar 1 -- en: Sound | |
delay 1 | |
click first checkbox of scroll area 1 of group 1 of window 1 whose name contains AIR_PODS_NAME | |
delay 1 | |
click checkbox "ノイズキャンセリング" of scroll area 1 of group 1 of window 1 -- en: Noise Cancellation | |
delay 1 | |
click menu bar item "サウンド" of menu bar 1 -- en: Sound | |
end tell | |
end tell | |
' | |
# 出力テスト | |
say -v samantha Connected | |
break | |
fi | |
done | |
break | |
fi | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
たまに音声出力切替に失敗する、ノイズコントロールモードがオフになっている問題を回避
以下のスクリプトを改変: