• BetterTouchTool で Mac の音声の出力をショートカットで変更する

    set currentOutput to do shell script "/opt/homebrew/Cellar/switchaudio-osx/1.2.2/SwitchAudioSource -c -t output"
    set availableDevices to do shell script "/opt/homebrew/Cellar/switchaudio-osx/1.2.2/SwitchAudioSource -a -t output"
    set nextDevice to ""
    
    if currentOutput contains "CalDigit TS4 Audio - Front" then
    	do shell script "/opt/homebrew/Cellar/switchaudio-osx/1.2.2/SwitchAudioSource -s \"LG ULTRAFINE\" -t output"
    	set nextDevice to "LG ULTRAFINE"
    	
    else if currentOutput contains "LG ULTRAFINE" then
    	-- USB speaker が存在するかチェック
    	if availableDevices contains "USB speaker" then
    		do shell script "/opt/homebrew/Cellar/switchaudio-osx/1.2.2/SwitchAudioSource -s \"USB speaker\" -t output"
    		set nextDevice to "USB speaker"
    	else
    		-- USB speaker がないときは CalDigit へ
    		do shell script "/opt/homebrew/Cellar/switchaudio-osx/1.2.2/SwitchAudioSource -s \"CalDigit TS4 Audio - Front\" -t output"
    		set nextDevice to "CalDigit TS4 Audio - Front"
    	end if
    	
    else
    	do shell script "/opt/homebrew/Cellar/switchaudio-osx/1.2.2/SwitchAudioSource -s \"CalDigit TS4 Audio - Front\" -t output"
    	set nextDevice to "CalDigit TS4 Audio - Front"
    end if
    
    -- HUD を表示
    set hudText to "🔊 " & nextDevice
    set hudCommand to "open \"btt://trigger_action/?json={\\\"BTTPredefinedActionType\\\":254,\\\"BTTPredefinedActionName\\\":\\\"Show HUD Overlay\\\",\\\"BTTHUDActionConfiguration\\\":\\\"{\\\\\\\"BTTActionHUDDetail\\\\\\\":\\\\\\\"" & hudText & "\\\\\\\",\\\\\\\"BTTActionHUDTitle\\\\\\\":\\\\\\\"Audio Output\\\\\\\",\\\\\\\"BTTActionHUDDuration\\\\\\\":1.5}\\\"}\""
    
    do shell script hudCommand