Send files to your phone from file manager

A very handy thing to have in your file manager is an option to send files directly to your phone.

If you happen to use KDE Connect and Dolphin, this is already there out of the box. Just right click a file and will see an option to send it to your devices. GNOME and Nautilus with the GSConnect extension provides the same.

But what if you use other file manager? You can replicate that functionality, and this post aims to help you on that.

The general idea is to:

  • Craft the right command to send the file.
  • Instruct the file manager to have it as a context menu item.

So let’s do it.

Step 1 - Install and configure KDE Connect

First of all, you need to have KDE Connect installed (both on your computer and your phone) and do the pairing.

Step 2 - Craft the command

KDE Connect has a CLI, kdeconnect-cli. Running it with -l provides a list of paired devices:

$ kdeconnect-cli -l

To send them a file, you can run:

$ kdeconnect-cli -d DEVICE_ID --share FILE_PATH

Or

$ kdeconnect-cli -n DEVICE_NAME --share FILE_PATH

Take a look at the output of the first command and replace DEVICE_ID or DEVICE_NAME accordingly, as well as FILE_PATH.

Step 3 - Setting the command on the file manager

Now you are able to send files to your phone by typing a command. The next step is to configure your file manager to offer to run that same command when you select a file.

The precise way to do that depends on which file manager you are using. I’ll briefly explain it for Thunar and Nemo.

Thunar

On Thunar, add a custom action.

Click on Edit - Configure custom actions. After clicking the + icon, paste the command you got from Step 2, replacing the file path by %f. You’ll have something like this:

kdeconnect-cli -d DEVICE_ID --share %f

In the tab “Appearance conditions” be sure to check all file types except “Directories”, as kdeconnect-cli can’t handle them.

Nemo

On Nemo, you can create a Nemo action. These are files very similar to desktop entries and are placed at ~/.local/share/nemo/actions/.

You can get mine here. Replace what is after Exec= with the command from Step 2, and change Selection=m to Selection=s.

Improving: Multiple files and notifications

If everything went well, you can now send a file to your phone just by right clicking it and selecting the option. Cool, uh?

However, there is room for improvement. As I pointed out, this setup doesn’t allow you to send more than one file per time. That’s a limitation from kdeconnect-cli. Also, you may want a notification if the sending was successful or not.

Both things can be achieved by writing a small wrapper script around kdeconnect-cli, and making your file manager call it instead of the former. Then, make the file manager allow multiple selection. For this, on Thunar replace %f with %F in your command; on Nemo, set Selection=m in your action.

If those improvements interest you, take a look at the next section.

My setup

I wrote a small wrapper script, which takes care of all the points above.

Some readers asked me for a step-by-step guide on setting it up, so I’ll describe it below.

On Nemo

  1. Download the script to your PATH and make it executable:
$ cd /usr/local/bin    # or anywhere in your PATH
$ sudo wget https://gist.githubusercontent.com/rc2dev/678adc40cd75f9ea472cd3f77b63d21c/raw/893032b9c60f510727fed20548a6be93e1048e81/send2phone -O send2phone
$ sudo chmod +x send2phone
  1. Download the Nemo action and place it in the appropriate directory:
$ mkdir -p ~/.local/share/nemo/actions
$ cd ~/.local/share/nemo/actions
$ wget https://gist.githubusercontent.com/rc2dev/678adc40cd75f9ea472cd3f77b63d21c/raw/893032b9c60f510727fed20548a6be93e1048e81/send2phone.nemo_action -O send2phone.nemo_action

On Thunar

  1. Download the script to your PATH and make it executable:
$ cd /usr/local/bin    # or anywhere in your PATH
$ sudo wget https://gist.githubusercontent.com/rc2dev/678adc40cd75f9ea472cd3f77b63d21c/raw/893032b9c60f510727fed20548a6be93e1048e81/send2phone -O send2phone
$ sudo chmod +x send2phone
  1. Open Thunar and create a custom action with the following command:
send2phone %F

As always, on “Appearance conditions” check everything except directories.

On ranger

If you prefer a terminal-based file manager, things are analogous. On ranger, just download the script to your PATH and add a line to your rc.conf:

map bp shell -f send2phone %s

Now you can select some files, press bp (or whatever shortcut you prefer) and they are sent to your phone.

Troubleshooting “No such object path”

If kdeconnect-cli is throwing a message like error: No such object path, take a look here.


Updates

  • : Add ranger.
  • : kdeconnect-cli now accepts relative paths.
  • : Add "no such object path" troubleshoot.
  • : Add a how-to for using my wrapper script.

  • All posts · Show comments