FedoraForum.org - Fedora Support Forums and Community
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2011
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hotkey: "Disable/Enable Bluetooth"

    Hi all,

    I'd like to have a bluetooth hotkey (Fn+F6), but in order to achieve this, I need a working script to toggle bluetooth state, which is stored in /proc/acpi/ibm/bluetooth (owned by root!).

    Usually I can simply enable/disable bluetooth by using the bluetooth-applet in the top bar of my gnome-shell. And this also changes the state in /proc/acpi/ibm/bluetooth.

    But when trying to change the state in terminal I get:

    Code:
    $ echo "disable" > /proc/acpi/ibm/bluetooth
    bash: /proc/acpi/ibm/bluetooth: Permission denied
    So obviously, this line won't work in a shell script that is supposed to be called by pressing a hotkey - the permissions won't suffice.

    What could such a bluetooth-toggle script look like to switch on/off bluetooth _without root permissions_?
    Last edited by tuxor; 26th November 2011 at 03:54 PM.
    Fedora on Lenovo ThinkPad T400s

  2. #2
    Join Date
    Jun 2010
    Location
    Lost...
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Disable/Enable Bluetooth Hotkey

    Hello,
    you can use acpi scripts. Look here: http://www.thinkwiki.org/wiki/How_to_setup_Bluetooth

    To restart acpid on fedora 16:
    Code:
    systemctl restart acpid.service
    By the way, you should not write into /proc. Use /sys for this.
    :confused:

  3. #3
    Join Date
    Mar 2011
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Disable/Enable Bluetooth Hotkey

    Thanks for your answer! acpid is not installed on my system and to be honest, I don't want to install another service just for this single hotkey. But I will take that method into consideration, if I can't find anything else.

    Using...
    Code:
    echo 1 > /sys/devices/platform/thinkpad_acpi/bluetooth_enable
    ...I'm still missing the sufficient permissions.

    There MUST be a way to toggle bluetooth without root permissions and _without_ using acpid, since bluetooth-applet can do this without root permissions and without acpid?!

    This is, how bluetooth-applet manages the Bluetooth-Killswitch: http://pastebin.com/3U4VKLtY
    This inspired me to install "rfkill". And now

    I finally found a solution!
    Code:
    #!/bin/bash
    
    BT_RFKILL=$(rfkill list | grep tpacpi_bluetooth_sw | sed 's/\([0-9]\+\):.*/\1/')
    BT_STATE=$(/sbin/rfkill list $BT_RFKILL | grep "Soft blocked: yes")
    
    if [ "x" == "x$BT_STATE" ]; then
    	/sbin/rfkill block $BT_RFKILL
    else
    	/sbin/rfkill unblock $BT_RFKILL
    fi
    
    exit 0
    Last edited by tuxor; 26th November 2011 at 04:32 PM.
    Fedora on Lenovo ThinkPad T400s

  4. #4
    Join Date
    Jul 2009
    Posts
    1,234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Disable/Enable Bluetooth Hotkey

    Using your rfkill script, I was able to toggle bluetooth as well.

    As root, I created the file /etc/acpi/actions/bluetooth.sh with the contents of your rfkill script. I then made the file executable from Nautilus as root by changing permissions.

    Next I ran acpi_listen in terminal to see what Fn+F9 showed. I was getting button/f24 F24 00000080 00000000. I then created the file /etc/acpi/events/bluetoothconf as root with the following contents:
    Code:
    event=button/f24.*
    action=/etc/acpi/actions/bluetooth.sh
    Finally I ran #acpid restart. Now my hotkey combo toggles the bluetooth radio on and off.

    An alternative for some might be to create a custom keyboard shortcut in System Settings > Keyboard > Shortcuts > Custom Shortcuts, however this was not working for me with the Fn+F9 shortcut.

    EDIT: After reboot I got some SELinux alerts. Had to run audit2allow 3 times (IIRC) to get SELinux to allow the rfkill script to run.
    Last edited by David Batson; 31st December 2011 at 05:03 PM.
    Fedora 19 Gnome on a ThinkPad X220, i5-2540M CPU, Intel HD Graphics 3000, Intel N 6205 wireless, and Sierra Wireless 754S Mobile Hotspot (AT&T)

  5. #5
    Join Date
    Dec 2022
    Location
    Ukraine
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Disable/Enable Bluetooth Hotkey

    You can set shortcut on command (I'm on Fedora 37):
    Code:
    rfkill toggle bluetooth

Similar Threads

  1. Bluetooth...disable/enable...?
    By JamesR in forum Using Fedora
    Replies: 15
    Last Post: 7th December 2016, 07:52 PM
  2. No Enable/Disable for the Services App
    By hbaird in forum Using Fedora
    Replies: 12
    Last Post: 30th October 2011, 05:28 PM
  3. Fedora 15 enable bluetooth
    By COKEDUDE in forum Guides & Solutions (Not For Questions)
    Replies: 5
    Last Post: 15th September 2011, 10:38 AM
  4. how to enable bluetooth
    By schneidz in forum Hardware
    Replies: 6
    Last Post: 13th June 2011, 01:13 AM
  5. FC3 yum.repos.d & how to enable/disable
    By cybrjackle in forum Guides & Solutions (Not For Questions)
    Replies: 8
    Last Post: 27th November 2004, 12:34 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •