dwmblocks 蓝牙模块。如何显示连接的设备名称?

dwmblocks 蓝牙模块。如何显示连接的设备名称?

我在用着密集波管理对于dwmblocks状态栏,我有多个模块/脚本运行用于状态,包括蓝牙脚本,用于在设备连接时显示一些信息和状态

 #!/bin/bash
  
  case $BLOCK_BUTTON in
          1) setsid -f blueman-manager ;;
          2) notify-send "$icon Device Connected" "$(if [[ "$(bluetoothctl info)" != "Missing device address argument" ]]; then 
                                                  echo= "$(bluetoothctl info | grep "Name" | awk '{print $2}')"
else
                                                  echo= "No Device Connected" )" ;;
          3) notify-send "$icon  Bluetooth" "\- Show Bluetooth Status.
  - Click to open Bluetooth Manager.
  - Middle click to show Connected Devices." ;;
  
  esac
  
    if [[ "$(bluetoothctl info)" != "Missing device address argument" ]]; then
      icon="  "
    else
      icon="  "
    fi
  
  printf "%s%s\\n" "$icon"

脚本工作正常,但中键单击操作

2) notify-send "$icon Device Connected" "$(if [[ "$(bluetoothctl info)" != "Missing device address argument" ]]; then 
                                                  echo= "$(bluetoothctl info | grep "Name" | awk '{print $2}')"
else
                                                  echo= "No Device Connected" )" ;;

不显示任何内容,我只希望它在设备连接时显示“设备已连接 -(设备名称)”,否则它显示“无设备连接”,但单击操作似乎不起作用。甚至不显示空白通知。

答案1

对于任何遇到问题的人

 #!/bin/sh
  case $BLOCK_BUTTON in
          1) setsid -f blueman-manager ;;
          2) notify-send "$icon Device Connected" "$(if [ "$(bluetoothctl info)" != "Missing device address argument" ]; then
                                                  echo= bluetoothctl info | grep "Name" | awk '{print $2}'
        else
            echo 'No Device Connected'
                          fi )" ;;
          3) notify-send "$icon  Bluetooth" "\- Show Bluetooth Status.
  - Click to open Bluetooth Manager.
  - Middle click to show Connected Devices." ;;

  esac

    if [ "$(bluetoothctl info)" != "Missing device address argument" ]; then
      icon="  "
    else
      icon="  "
    fi

  printf "%s\\n" "$icon"

这是我改变的。

2) notify-send "$icon Device Connected" "$(if [ "$(bluetoothctl info)" != "Missing device address argument" ]; then
                                                      echo= bluetoothctl info | grep "Name" | awk '{print $2}'
            else
                echo 'No Device Connected'
                              fi )" ;;
  1. IF 语句没有关闭,我关闭了它
  2. 当第一个参数满足“不等于“缺少设备地址参数””的要求时,echo 将作为命令替换运行,并且会失败
  3. 当没有连接设备时,echo 将作为命令替换运行,并且会失败。我们希望它只是回显没有连接设备。

有关更多信息,请查看此资源(https://github.com/koalaman/shellcheck/wiki/SC2091

    printf "%s\\n" "$icon"

原始脚本提供了 2 个字符串,但仅通过了

相关内容