KDE Connect/Tutorials/Useful commands

From KDE UserBase Wiki

List of example commands for KDE Connect

In KDE Connect, you can add your own commands and execute them from your phone. Here are some useful commands. Feel free to add your own!

Control your computer state

  • Shutdown:
    systemctl poweroff
  • Reboot:
    systemctl reboot
  • Suspend:
    systemctl suspend
  • Hibernate:
    systemctl hibernate
  • Lock screen:
    loginctl lock-session
  • Unlock screen:
    loginctl unlock-session
  • Turn off screen:
    sleep 0.1 && qdbus org.kde.kglobalaccel /component/org_kde_powerdevil invokeShortcut "Turn Off Screen"
  • Lock keyboard and mouse (not the screen):
    pyxtrlock
  • Unlock keyboard and mouse:
    pkill pyxtrlock

Volume control

Plasma

  • Volume down:
    qdbus org.kde.kglobalaccel /component/kmix invokeShortcut "decrease_volume"
  • Volume up:
    qdbus org.kde.kglobalaccel /component/kmix invokeShortcut "increase_volume"
  • Mute:
    qdbus org.kde.kglobalaccel /component/kmix invokeShortcut "mute"
  • Mute microphone:
    qdbus org.kde.kglobalaccel /component/kmix invokeShortcut "mic_mute"

Other DE/WM (with pactl)

  • Volume down:
    pactl set-sink-volume @DEFAULT_SINK@ -10%
    ## OR
    pactl set-sink-volume $(pactl list short sinks | grep RUNNING | cut -f1) -10%
    
  • Volume up:
    pactl set-sink-volume @DEFAULT_SINK@ +10%
    ## OR
    pactl set-sink-volume $(pactl list short sinks | grep RUNNING | cut -f1) +10%
    
  • Mute/Unmute:
    pactl set-sink-mute @DEFAULT_SINK@ toggle
    ## OR
    pactl set-sink-mute $(pactl list short sinks | grep RUNNING | cut -f1) toggle
    

Other DE/WM (with amixer)

  • Volume down:
    amixer -q sset Master 10%-
  • Volume up:
    amixer -q sset Master 10%+

Other commands can be built using amixer

Change look and feel

  • Breeze (Light) theme:
    lookandfeeltool -a 'org.kde.breeze.desktop'
  • Breeze (Dark) theme:
    lookandfeeltool -a 'org.kde.breezedark.desktop'

Brightness settings

  • Brightness Up:
    qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/BrightnessControl org.kde.Solid.PowerManagement.Actions.BrightnessControl.setBrightness $(expr $(qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/BrightnessControl org.kde.Solid.PowerManagement.Actions.BrightnessControl.brightness) + 375)
  • Brightness Down:
    qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/BrightnessControl org.kde.Solid.PowerManagement.Actions.BrightnessControl.setBrightness $(expr $(qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/BrightnessControl org.kde.Solid.PowerManagement.Actions.BrightnessControl.brightness) - 375)

Screen capture

  • Save locally:
    spectacle -b
  • Send to phone:
    file=/tmp/$(hostname)_$(date "+%Y%m%d_%H%M%S").png; spectacle -bo "${file}" && while ! [ -f "${file}" ]; do sleep 0.5; done && kdeconnect-cli -d $(kdeconnect-cli -a --id-only) --share "${file}"
  • Save webcam photo in the Images folder and send to phone:
    file="$HOME/Images/WebcamImage_$(date "+%Y%m%d_%H%M%S").jpg"; ffmpeg -f video4linux2 -s 1280x720 -i /dev/video0 -ss 0:0:2 -frames 1 "${file}" && kdeconnect-cli -d $(kdeconnect-cli -a --id-only) --share "${file}"

Send output of any command to your phone

  • Check the status of baloo indexing:
    kdeconnect-cli -d $(kdeconnect-cli -a --id-only) --ping-msg "$(balooctl status)"
  • Check lines 5, 7 and 9 of speedtest-cli:
    kdeconnect-cli -d $(kdeconnect-cli -a --id-only) --ping-msg "$(speedtest-cli|awk 'NR==5;NR==7;NR==9 {print;exit}')"
  • Check whether service sshd is running:
    kdeconnect-cli -d $(kdeconnect-cli -a --id-only) --ping-msg "$(systemctl status sshd|grep Active)"
  • Check the top 5 applications using most RAM:
    kdeconnect-cli -d $(kdeconnect-cli -a --id-only) --ping-msg "$(ps -eo pid,%mem,cmd --sort=-%mem | head -n 6)"

Windows Specific Commands

The location for runcommands created in the application, if you decide to copy them can be found in:

First go to: C:\Users\%USERNAME%\AppData\Local\Packages\

then find KDE folder and navigate down to kdenconnect folder ..\KDEe.V.KDEConnect_[HASH]\LocalCache\Local\kdeconnect


Within the folder you'll find folders that are specific to paired devices with the format:

deviceid/kdeconnect_runcommand/config

if yours has a config file, this config file is what you copy between other device ids to use the same commmands elsewhere. Then that paired device has the commands you created within the KDE windows app from a remote device.

If it doesn't have a config file, you didn't set up custom commands in the kde windows application.


The commands will generally in one of three ways:

1.) Anything specific to rundll32 commands or user32 dll commands e.g. "Rundll32.exe user32.dll,LockWorkStation"

2.) Commands that you would run via the shell/powershell/or command prompt "start powershell -NoExit -command <command>" (start and powershell are optional -NoExit flag to keep window from closing) and so are similar to launching it from the start menu.

3.)Finally, the third option here is using software called Nircmd


("Start Powershell" is optional, as nircmd can run without having to show a shell prompt) So more than one format is provided.

Example Windows commands include:

  • Lock Station
Rundll32.exe user32.dll,LockWorkStation
  • Unlock Workstation


  • Toggle Mute
start powershell -command nircmd mutesysvolume 2
  • Mute System Volume
start powershell -command nircmd mutesysvolume 1
  • UnMute System Volume
start powershell -command nircmd mutesysvolume 0
  • System Volume 25%
start powershell -command nircmd nircmd.exe setsysvolume 16383.75
  • System Volume 50%
start powershell -command nircmd nircmd.exe setsysvolume 32767.5
  • System Volume 75%
start powershell -command nircmd nircmd.exe setsysvolume 49151.25
  • System Volume 100%
start powershell -command nircmd nircmd.exe setsysvolume 65535
  • System Volume Up 2000 units (out of 65535) - Number Value Can be to whatever way you prefer, but the volume shifts by that %
nircmd changesysvolume 2000
  • System Volume Down 5000 units (out of 65535)
nircmd.exe changesysvolume -5000
  • Shutdown Computer
start powershell -command exitwin poweroff
  • Mute Mic

WIP

  • Immediate Shutdown
shutdown /s /t 0
  • Restart Computer
shutdown /r
  • Cancel Shutdown
shutdown /a

Youtube control and media control can also be done via simulated keypresses through nircmd. You can either set them to your preference.

    • To extend further, commands run via and android phone open a URL, opening that URL launches the command -> and so use of that command via tasker, or KWGT is possible.

For example :

Remapping to KDE connect the bottom become: If nircmd installed to windows directory

  • Like Song

nircmd sendkeypress plus

  • Next Song

nircmd sendkeypress j

  • Previous Song

nircmd sendkeypress k

  • Shuffle Queue

nircmd sendkeypress s

  • Toggle Repeat

nircmd sendkeypress r

  • Volume up

nircmd sendkeypress shift+plus

  • Volume down

nircmd sendkeypress minus

  • Mute

nircmd sendkeypress m



More commands can be found at, use at your own risk:

For Rundll32 here and here

For Powershell here and here

For nircmd: here