This article explains how to execute shell commands on a Linux computer from an android smartphone and a WearOS smartwatch.
- Linux computers can communicate with android smartphones using KDEConnect.
- If you purchase the tasker android app for $3.49, you can set up a notification task that can be pushed to your smartwatch.
- I was awarded the r/unixporn post of the month for a demo video that I posted here.
Launching scripts from an Android device
Before you can launch scripts from a smartwatch, you need to be able to launch scripts from a smartphone. The instructions below are for an arch linux based distribution running i3WM, but there are plenty of guides on the internet - just search for “How to install KDEConnect on <insert your distro here>.”
- Install KDEConnect on your Linux machine with
sudo pacman -Syu kdeconnect
exec --no-startup-id /usr/lib/kdeconnectdto your i3 config
- Restart your i3 session
- Download the kdeconnect app on your android device. Open it.
- Open up the kdeconnect application on Linux and pair to your android device.
- Add commands that you want to run. Change other settings as you please.
At this point, you should be able to run commands from your phone. Consider adding the KDEConnect command widget to your android home screen. If you don’t know what I’m talking about, Google “android widgets” or something like that.
Launching scripts from Wear OS smartwatch
- I could only figure out how to launch scripts from a smartwatch by using Tasker, which costs $3.49. It’s a pretty cool app though with tons of functionality, so it’s a fair deal. You might have luck with free alternative android applications, such as Automate or MacroDroid. Here’s the Tasker strategy:
- Download Tasker from Google Play
- For each KDEConnect command that you want on your watch (a maximum of 3):
- Copy the command URL by pressing and holding the command
- Go to the tasks tab on Tasker
- Add the following action: Net -> Browse URL. Paste your URL in the prompt.
- Click the add button and name the task whatever you want it to be
- Once you have your tasks ready, add another task that will serve as the notification dialogue
- Add the following action: Alert -> Notify
- Fill out title and optionally the text, add notification icon, etc. Make sure that the notification is not set to permanent. At the bottom of the screen, you’ll see “Actions.” Add your tasks from the previous step (the KDEConnect commands) here.
- At the bottom of the screen, you’ll see “Actions.” Add your tasks from the previous step (the KDEConnect commands) here.
- Repeat 1-3 for each of your KDEConnect command tasks.
- Launch the notification task in Tasker by clicking on its name under the Tasks tab and hitting the play button. This will send it to your watch’s notification screen.