You are not logged in.
I wanted to create a service that will turn off Bluetooth in my laptop if no device is connected for 10 minutes
cat /etc/systemd/system/disable-bluetooth.service
[Unit]
Description=Disable Bluetooth if no devices are connected and running on battery
[Service]
Type=oneshot
ExecStart=/usr/bin/bash -c 'devices_connected=$(bluetoothctl devices Connected | wc -l); power_status=$(cat /sys/class/power_supply/AC/online); if [ "$devices_connected" -eq 0 ] && [ "$power_status" -eq 0 ]; then systemctl stop bluetooth; fi'Tried with
ExecStart=/usr/bin/bash -c 'bluetooth_status=$(bluetoothctl info | grep "Connected: yes"); power_status=$(cat /sys/class/power_supply/AC/online); if [ -z "$bluetooth_status" ] && [ "$power_status" -eq 0 ]; then systemctl stop bluetooth; fi'Just to be sure
cat /etc/systemd/system/disable-bluetooth.timer
[Unit]
Description=Run Disable Bluetooth service every 10 minutes
[Timer]
OnUnitInactiveSec=10m
Unit=disable-bluetooth.service
[Install]
WantedBy=timers.targetIt doesn't work.
I use KDE Plasma.
When I do the test with
systemctl start disable-bluetooth.service
I can see that Bluetooth icon on the taskbar disappear for a fraction of a second and it shows up immediately
Last edited by 860lacov (2023-11-10 22:49:39)
Offline
Why not a timer linked to something incorporating # systemctl stop && disable bluetooth instead of "stop"? Same with "enable && start" instead of "start".
Last edited by c00ter (2023-11-11 04:54:07)
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things. -- Doug Gwyn
Offline
Why not a timer linked to something incorporating # systemctl stop && disable bluetooth instead of "stop"? Same with "enable && start" instead of "start".
To be honest I don't understand what's on your mind
Offline