Add bluetooth_connect.pl

This commit is contained in:
2024-07-13 21:18:10 +01:00
parent b10413ff5f
commit 06e7680c82
2 changed files with 36 additions and 0 deletions

View File

@ -5,6 +5,7 @@
- `bluetooth-off.sh`: script for disabling bluetooth with bluetoothcl on a system that uses - `bluetooth-off.sh`: script for disabling bluetooth with bluetoothcl on a system that uses
runit as its init system (such as Void GNU/Linux). runit as its init system (such as Void GNU/Linux).
- `bluetooth-on.sh`: Same as `bluetooth-off.sh` but for enabling bluetooth. - `bluetooth-on.sh`: Same as `bluetooth-off.sh` but for enabling bluetooth.
- `bluetooth_connect.pl`: Perl script that allows the user to select a bluetooth device to connect to via `dmenu`.
- `bluetooth_info.pl`: Perl script to display information about connected bluetooth devices. Designed to be used with polybar. - `bluetooth_info.pl`: Perl script to display information about connected bluetooth devices. Designed to be used with polybar.
- `bspwm_window_count.sh`: script for listing the number of open windows on the current "desktop" (workspace) with the bspwm window manager. - `bspwm_window_count.sh`: script for listing the number of open windows on the current "desktop" (workspace) with the bspwm window manager.
Primarily for use in status bars as indicator that windows may be hidden behind another when in floating or monocle mode. Primarily for use in status bars as indicator that windows may be hidden behind another when in floating or monocle mode.

35
bluetooth_connect.pl Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/perl
use strict;
use warnings;
my $script_name = $1 if ($0 =~ /.*\/(.*)$/);
my $output = `bluetoothctl devices`;
my %devices;
# assumes devices have unique names
foreach my $device (split(/\n/, $output)) {
if ($device =~ /Device\s(\S+)\s(.+)/) {
my $mac_address = $1;
my $name = $2;
$devices{$name} = $mac_address;
}
}
my $device_list = "";
foreach my $name (keys %devices) {
$device_list .= $name . "\n";
}
my $selection = `echo "$device_list" | dmenu`;
chomp($selection);
`notify-send "$script_name" "Attempting to connect to $selection"`;
`bluetoothctl connect $devices{$selection}`;
if ($? == 0) {
`notify-send "$script_name" "Successfully connected to $selection"`;
}
else {
`notify-send "$script_name" "Failed to connect to $selection"`;
}