Last active
November 5, 2024 15:15
-
-
Save vfmatzkin/a64c225ef4a0ff689c668a4049ad80f2 to your computer and use it in GitHub Desktop.
Bluetooth Autoconnect toggle on Windows with AutoHotKey
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
/* | |
Bluetooth Device Manager Script | |
Author: Franco Matzkin (vfmatkzin.github.io) | |
When I turn on my laptop, it automatically connects to my home bluetooth speakers. | |
This connection can disrupt ongoing calls or media playback, requiring me to manually | |
disconnect the speakers. This process takes time and may cause audio issues, | |
particularly if I'm in a call or watching something important. Using this script, | |
I can quickly disable the speakers from auto-connecting, allowing for a smoother | |
experience when starting my laptop. | |
Description: | |
This AutoHotkey script manages Bluetooth speaker devices on Windows. | |
Windows does not provide an option to disable Bluetooth auto-connect | |
without unpairing devices. This script allows to disable Bluetooth | |
devices in the Device Manager, preventing automatic connection while | |
keeping them paired. Devices can be re-enabled later. | |
Features: | |
- Enable and disable individual Bluetooth speakers (Room, Bathroom, Living, Kitchen). | |
- Enable and disable all Bluetooth speakers with a single action. | |
- Simple modification of device IDs for easy management. | |
Important: | |
Run this script with administrator privileges to change device states | |
in the Device Manager. | |
Usage: | |
1. Save this script as a `.ahk` file. | |
2. Right-click the file and select "Run as administrator." | |
3. Use the tray icon to manage your Bluetooth speakers. | |
Extracting Device IDs: | |
To obtain the device IDs: | |
1. Open Device Manager. | |
2. Find your Bluetooth devices under "Bluetooth" or "Sound, video and game controllers." | |
3. Right-click on the device and select "Properties." | |
4. Go to the "Details" tab and select "Device instance path" from the drop-down menu. | |
5. Copy the value shown. This is the device ID to use in the script. | |
Note: Replace the placeholder device IDs in the script with the actual IDs | |
of your Bluetooth speakers for proper functionality. | |
*/ | |
#Persistent | |
#NoEnv | |
; Define device IDs for speakers | |
roomSpeakerID := "BTHENUM\{0000110E-0000-1000-8000-00805F9B34FB}_VID&0001000F_PID&1200\7&B9602B&0&201F3BBFD4A1_C00000000" ; Room | |
bathroomSpeakerID := "BTHENUM\{0000110E-0000-1000-8000-00805F9B34FB}_VID&0001000F_PID&1200\7&B9602B&0&F0EF865DAB6E_C00000000" ; Bathroom | |
livingSpeakerID := "BTHENUM\{0000110E-0000-1000-8000-00805F9B34FB}_LOCALMFG&0002\7&B9602B&0&201F3BB2848C_C00000000" ; Living | |
kitchenSpeakerID := "BTHENUM\{0000110E-0000-1000-8000-00805F9B34FB}_VID&0001000F_PID&1200\7&B9602B&0&CCF411DAED09_C00000000" ; Kitchen | |
; Set up the tray icon | |
Menu, Tray, Icon, Shell32.dll, 42 ; Use a system icon | |
Menu, Tray, Tip, Device Manager | |
Menu, Tray, Add, Disable All Devices, DisableAll | |
Menu, Tray, Add, Enable All Devices, EnableAll | |
; Create submenus for each device | |
Menu, RoomDevice, Add, Enable, EnableRoom | |
Menu, RoomDevice, Add, Disable, DisableRoom | |
Menu, Tray, Add, Room Speaker, :RoomDevice | |
Menu, BathroomDevice, Add, Enable, EnableBathroom | |
Menu, BathroomDevice, Add, Disable, DisableBathroom | |
Menu, Tray, Add, Bathroom Speaker, :BathroomDevice | |
Menu, LivingDevice, Add, Enable, EnableLiving | |
Menu, LivingDevice, Add, Disable, DisableLiving | |
Menu, Tray, Add, Living Speaker, :LivingDevice | |
Menu, KitchenDevice, Add, Enable, EnableKitchen | |
Menu, KitchenDevice, Add, Disable, DisableKitchen | |
Menu, Tray, Add, Kitchen Speaker, :KitchenDevice | |
Menu, Tray, Add, Exit, ExitApp | |
Menu, Tray, Default, Disable All Devices | |
return | |
; Enable All Devices | |
EnableAll: | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%roomSpeakerID%' | Enable-PnpDevice -Confirm:$false", , Hide | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%bathroomSpeakerID%' | Enable-PnpDevice -Confirm:$false", , Hide | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%livingSpeakerID%' | Enable-PnpDevice -Confirm:$false", , Hide | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%kitchenSpeakerID%' | Enable-PnpDevice -Confirm:$false", , Hide | |
return | |
; Disable All Devices | |
DisableAll: | |
; First enable all devices, then disable them | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%roomSpeakerID%' | Enable-PnpDevice -Confirm:$false", , Hide | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%bathroomSpeakerID%' | Enable-PnpDevice -Confirm:$false", , Hide | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%livingSpeakerID%' | Enable-PnpDevice -Confirm:$false", , Hide | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%kitchenSpeakerID%' | Enable-PnpDevice -Confirm:$false", , Hide | |
Sleep, 5000 ; Wait for 5 seconds before disabling | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%roomSpeakerID%' | Disable-PnpDevice -Confirm:$false", , Hide | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%bathroomSpeakerID%' | Disable-PnpDevice -Confirm:$false", , Hide | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%livingSpeakerID%' | Disable-PnpDevice -Confirm:$false", , Hide | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%kitchenSpeakerID%' | Disable-PnpDevice -Confirm:$false", , Hide | |
return | |
; Enable Room Speaker | |
EnableRoom: | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%roomSpeakerID%' | Enable-PnpDevice -Confirm:$false", , Hide | |
return | |
; Disable Room Speaker | |
DisableRoom: | |
; First enable the device, then wait and disable it | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%roomSpeakerID%' | Enable-PnpDevice -Confirm:$false", , Hide | |
Sleep, 5000 ; Wait for 5 seconds before disabling | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%roomSpeakerID%' | Disable-PnpDevice -Confirm:$false", , Hide | |
return | |
; Enable Bathroom Speaker | |
EnableBathroom: | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%bathroomSpeakerID%' | Enable-PnpDevice -Confirm:$false", , Hide | |
return | |
; Disable Bathroom Speaker | |
DisableBathroom: | |
; First enable the device, then wait and disable it | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%bathroomSpeakerID%' | Enable-PnpDevice -Confirm:$false", , Hide | |
Sleep, 5000 ; Wait for 5 seconds before disabling | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%bathroomSpeakerID%' | Disable-PnpDevice -Confirm:$false", , Hide | |
return | |
; Enable Living Speaker | |
EnableLiving: | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%livingSpeakerID%' | Enable-PnpDevice -Confirm:$false", , Hide | |
return | |
; Disable Living Speaker | |
DisableLiving: | |
; First enable the device, then wait and disable it | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%livingSpeakerID%' | Enable-PnpDevice -Confirm:$false", , Hide | |
Sleep, 5000 ; Wait for 5 seconds before disabling | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%livingSpeakerID%' | Disable-PnpDevice -Confirm:$false", , Hide | |
return | |
; Enable Kitchen Speaker | |
EnableKitchen: | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%kitchenSpeakerID%' | Enable-PnpDevice -Confirm:$false", , Hide | |
return | |
; Disable Kitchen Speaker | |
DisableKitchen: | |
; First enable the device, then wait and disable it | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%kitchenSpeakerID%' | Enable-PnpDevice -Confirm:$false", , Hide | |
Sleep, 5000 ; Wait for 5 seconds before disabling | |
Run, PowerShell.exe -Command "Get-PnpDevice -InstanceId '%kitchenSpeakerID%' | Disable-PnpDevice -Confirm:$false", , Hide | |
return | |
; Exit the script | |
ExitApp: | |
ExitApp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment