Ubuntu – Setting a hotkey for connecting and disconnecting a network connection in KDE environment

ccommand linekdenetworkingshortcut-keys

Is there a way to set a hotkey for toggling connection through a network cable:

enter image description here


Also if I have a command in command-line that can do this or a piece of C++ code that does this I can set a hotkey for it.

Best Answer

Control of the NetworkManger

The NetworkManger can be controlled from the commandline:

man nmcli:

NAME
       nmcli – command‐line tool for controlling NetworkManager

SYNOPSIS
       nmcli  [ OPTIONS ] OBJECT { COMMAND | help }
...

The man page on the net: http://manpages.ubuntu.com/manpages/saucy/man1/nmcli.1.html

With the dbus:

Example - working at here:

Disconnecting from the current network connection and staying disconnected:

qdbus --system --literal  org.freedesktop.NetworkManager /org/freedesktop/NetworkManager/Devices/0 org.freedesktop.NetworkManager.Device.Disconnect

Connecting the network with th UUID:

1) Reading the UUID:

nmcli -p c

At here the UUID is 81540c01-2377-4d79-9763-d0f3104c81f3

2) Activating the connection:

nmcli c up uuid 81540c01-2377-4d79-9763-d0f3104c81f3

Hotkeys

One way to add the shortcuts/hotkeys is to use the KDE menu editor.

enter image description here

The command can be added to the KDE menu with a shortcut to run the command.

The KDE document can be found: K-Menu > Applications > Help ...

The KDE menu editor handbook on the net: http://docs.kde.org/development/en/kde-workspace/kmenuedit/index.html

Related Question