Last active
July 19, 2024 10:06
-
-
Save yuki777/99e6ff70202ccb04ae982ad72d158376 to your computer and use it in GitHub Desktop.
reset-sound-device.app
This file contains hidden or 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
# https://apple.stackexchange.com/questions/190319/display-notification-works-from-applescript-editor-but-not-when-exported-as-ap | |
tell application "Finder" to activate | |
# Krispを終了する | |
do shell script "killall krisp || true" | |
# Krispの終了を待つ | |
repeat | |
delay 1 | |
try | |
set krispRunning to do shell script "/usr/bin/pgrep -x krisp" | |
on error | |
set krispRunning to "" | |
end try | |
if krispRunning is "" then exit repeat | |
end repeat | |
# Krispを起動する | |
do shell script "open ~/Applications/krisp.app" | |
# Krispの起動を待つ | |
repeat | |
delay 1 | |
try | |
set krispRunning to do shell script "/usr/bin/pgrep -x krisp" | |
on error | |
set krispRunning to "" | |
end try | |
if krispRunning is not "" then exit repeat | |
end repeat | |
# System Settingsアプリを起動し、Soundの設定を開く | |
tell application "System Settings" | |
activate | |
reveal pane "Sound" | |
end tell | |
# 入力デバイスを指定する | |
do shell script " | |
/opt/homebrew/bin/SwitchAudioSource -f json -t input -s 'Yeti Nano' || | |
/opt/homebrew/bin/SwitchAudioSource -f json -t input -s 'External Headphones' || | |
/opt/homebrew/bin/SwitchAudioSource -f json -t input -s 'YukiAirPodsPro' || | |
/opt/homebrew/bin/SwitchAudioSource -f json -t input -s 'MacBook Pro Microphone' | |
" | |
# 入力音量を80%に設定する | |
set volume input volume 80 | |
# 出力デバイスを指定する | |
do shell script " | |
/opt/homebrew/bin/SwitchAudioSource -f json -t output -s 'External Headphones' || | |
/opt/homebrew/bin/SwitchAudioSource -f json -t output -s 'YukiAirPodsPro' || | |
/opt/homebrew/bin/SwitchAudioSource -f json -t output -s 'Soundcore Life P2' || | |
/opt/homebrew/bin/SwitchAudioSource -f json -t output -s 'MacBook Pro Speakers' | |
" | |
# 現在の出力デバイスを取得する | |
set currentOutputDevice to do shell script "/opt/homebrew/bin/SwitchAudioSource -c -t output" | |
# 出力音量を設定する | |
if currentOutputDevice = "External Headphones" then | |
set volume output volume 70 | |
else if currentOutputDevice = "YukiAirPodsPro" then | |
set volume output volume 70 | |
else if currentOutputDevice = "Soundcore Life P2" then | |
set volume output volume 60 | |
else if currentOutputDevice = "MacBook Pro Speakers" then | |
set volume output volume 70 | |
else | |
set volume output volume 75 | |
end if | |
# 現在の入力デバイスを取得する | |
set currentInputDevice to do shell script "/opt/homebrew/bin/SwitchAudioSource -c -t input" | |
# 入出力デバイスを表示する | |
display notification "🎤 " & currentInputDevice & " | |
🔈 " & currentOutputDevice with title "reset-sound.app" sound name "Glass" | |
# フィードバックサウンドを再生する | |
do shell script "/usr/bin/afplay /System/Library/Sounds/Glass.aiff" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment