diff --git a/README.md b/README.md index abaf5f6..f4d89b7 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ - `bluetooth-off.sh`: script for disabling bluetooth with bluetoothcl on a system that uses runit as its init system (such as Void GNU/Linux). - `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. - `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. diff --git a/bluetooth_connect.pl b/bluetooth_connect.pl new file mode 100755 index 0000000..52bd9a8 --- /dev/null +++ b/bluetooth_connect.pl @@ -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"`; +}