Ubuntu – How tontegrate Dropbox in Thunar

bashdropboxscriptsthunarxfce

How can I integrate Dropbox into Thunar? I am using Xubuntu 14.04 with Xfce 4.12 installed via PPA, and thunar-dropbox-plugin has been broken. I have also heard that it is not working on Xubuntu 16.04.

Best Answer

Fortunately, Dropbox recently expanded their CLI capabilities to include sharelinks etc. To integrate Dropbox into Thunar do the following:

Initial Setup

Create a ~/bin directory in your home folder if not already created. Download the Dropbox python script. Rename it as just dropbox. (The extension is not needed.) Make it executable chmod +x ~/bin/dropbox.

If the ~/bin directory is not already added to your $PATH (i.e. tab completion doesn't work for the script, etc.), you would add the following to ~/.profile. Then log out and in again.

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

Install xsel by pasting sudo apt-get install xsel in terminal. This program gives clipboard functionality to the below script.

Save the following script to a plain text file, save it in ~/bin, and make it executable. Mine is named dropbox-online. Change icon_path="/full/path/to/dropbox-icon.png" to the path to your Dropbox icon.

#!/bin/bash

# Name:     Dropbox Thunar Integration
# Author:   jbrock
# Dependencies: xsel (in Ubuntu repository), Dropbox python script https://linux.dropbox.com/packages/dropbox.py
# Installation: http://askubuntu.com/questions/777878/how-to-integrate-dropbox-in-thunar

notify_time=5000
icon_path="/full/path/to/dropbox-icon.png"
internet_status=$(ping -c 1 dropbox.com > /dev/null 2>&1; echo $?)
dropbox_status=$(dropbox status)

web_directory () {
    prepend_path="https://www.dropbox.com/home/"
    append_path=$(pwd | cut -d "/" -f5-)
    xdg-open "$prepend_path$append_path"
}

gui_notify () {
    notify-send -t "$notify_time" -i "$icon_path" "$1"
}

# Check: 1. internet connection; 2. if Dropbox is running; 3. if in Dropbox or Public folder.

if [ "$internet_status" != 0 ]; then
    gui_notify "There is an internet connectivity issue."
    exit 1
fi

if [ "$dropbox_status" = "Dropbox isn't running!" ]; then
    gui_notify "Dropbox isn't running."
    exit 1
fi

if [[ "$2" != *Dropbox* ]]; then
    gui_notify "You are not in Dropbox."
    exit 1
fi  

if [[ "$1" = -p && "$2" != *Dropbox\/Public* ]]; then
    gui_notify "You are not in the Dropbox/Public folder."
    exit 1
fi

case "$1" in
    -p )
        dropbox puburl "$2" | tr -d '\n' | xsel -ib && gui_notify "Public Link Copied" ;;
    -s )
        dropbox sharelink "$2" | tr -d '\n' | xsel -ib && gui_notify "Share Link Copied" ;;
    -d )
        web_directory ;;
esac

Thunar Integration

To integrate into Thunar. Go to Edit > Configure custom actions. Click the plus to add a custom action. Set up the following three custom actions:

Add Share Link

Add Public Link

Add Directory Online

Remember too that you can add your own icon to appear on the Thunar context menu items.

For each of these you'll want to do the following on the second tab given that you want to be able to share any type of file or directory.

Appearance Conditions

The only downside is that the three Dropbox menu items appear globally in Thunar, not only in Dropbox. However, the script tells you if you are accidentally outside of Dropbox.

Update: The command dropbox puburl no longer works. Dropbox no longer has the Public folder for free accounts and discontinues it for paid ones on September 1, 2017.