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.

But what if you use other file manager? You could 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, if you haven’t already, you need to install KDE Connect (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. FILE_PATH should be replaced by the full path of the file.

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 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/.

A sample file describing the options available is here .

Place the command from Step 2 in the Exec= line. Replace the file path for %F.

Also, you should use Selection=s and Extensions=nodirs, as kdeconnect-cli can’t handle directories or multiple files. And Quotes=double so the paths are enclosed.

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 said, this setup doesn’t allow you to send more than one file per time. That’s a limitation from kdeconnect-cli.

To overcome this, you can write a small wrapper script around kdeconnect-cli. Then, configure the file manager to call it instead, and allow for multiple selection. For the later, on Thunar replace %f with %F in your command; on Nemo, set Selection=m in your action.

Additionally, you may want a notification if the sending was successful. A wrapper script can also achieve that, checking the return value from kdeconnect-cli and calling notify-send with a friendly message.

My setup

It may be useful for you to look at my setup.

This is my wrapper script, which takes care of the points above. And as I am currently using Nemo, this is my Nemo action.

Update: using my setup

Some readers asked me for a step-by-step guide on setting up my wrapper script, 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://rafaelc.org/permalink/send2phone-raw -O send2phone
    $ sudo chmod +x send2phone
    
  2. Download the Nemo action and place it in the appropriate directory:

    $ mkdir -p ~/.local/share/nemo/actions
    $ cd ~/.local/share/nemo/actions
    $ wget https://rafaelc.org/permalinks/send2phone-nemo-raw -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://rafaelc.org/permalinks/send2phone-raw -O send2phone
    $ sudo chmod +x send2phone
    
  2. Open Thunar and create a custom action with the following command:

    send2phone %F
    

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