It has been a couple of weeks that I started using Dropbox to get my files synced, to backup actually. The Dropbox client for Fedora works well but still allows only to have a single directory (Dropbox directory) and whatever files or directories you put to the Dropbox directory will get synced.
Say you want to sync a text document that your are working on and the file resides in the Desktop (and Desktop is not your Dropbox directory). So basically what you can do is to move the file to your Dropbox directory and edit it from there. But in Fedora (or any other GNU/Linux distribution), you can have a symbolic link to the file and move the link to the Dropbox directory. In this case your file resides where it want to be (Desktop) and whatever changes you do will get synced due to the symbolic link.
Even this I found difficult when there are so many files to deal with. So I thought to write a nautilus script. Following is the code I wrote,
#!/bin/sh
#
# W.H. Kalpa Pathum <callkalpa@gmail.com>
# 1st June, 2010
#
# Dropbox directory
DROPBOX_DIR="$HOME/Dropbox/"
# creates a temporary file
file_list=$(mktemp)
# writes the URIs of the selected file to the temp file
echo $NAUTILUS_SCRIPT_SELECTED_URIS | sed 's/ \//\n/g' > $file_list
# iterete through the file list
for file in $(cat $file_list)
do
# extract the last filed from the URI, that is the file name
filename="$(echo $file | awk -F'/' '{print $NF}' | sed 's/%20/ /g')"
# creates the symbolic link
ln -s "$(pwd)/$filename" "$DROPBOX_DIR$filename"
# sets the emblem
gvfs-set-attribute -t stringv "$filename" metadata::emblems default
done
exit 0
To use this script,
- download the file from the link below
- open the file in a text editor like gedit
- replace $HOME/Dropbox/ with the path to your Dropbox directory
- copy the file to ~/.gnome2/nautilus-scripts/
- give the file the execute permissions
cd ~/.gnome2/nautilus-scripts
chmod +x <your file name>
Great !! Thanks for sharing this tips and script :)
ReplyDeleteI only just install for the first time Dropbox, but your script is pretty cool.
Best regard from France.
Sylvain
very useful script! thanks for sharing :)
ReplyDelete1. tray to replace
ReplyDeleteDROPBOX_DIR="$HOME/Dropbox/"
to be more universal:
query(){
echo "SELECT value
FROM config
WHERE key = 'dropbox_path'; "
}
mydb="$HOME/.dropbox/dropbox.db"
SQLITE_SELECT=$( sqlite3 "$mydb" "$(query)" )
DROPBOX_DIR="$(echo $SQLITE_SELECT \
| base64 -d \
| sed -e's/^V//g' \
| head -n 1)"
but I'm not so sure is this ok, because I got "V"(?!) before path.
2. remember to remove temporary file on exit
file_list=$(mktemp)
trap "rm -f $file_list" EXIT
3. or better, don't use it
echo $NAUTILUS_SCRIPT_SELECTED_URIS \
| sed 's/ \//\n/g' \
| while read -r file
do
...
done
@Sylvain and @agony
ReplyDeleteThanks for your comments and your welcome
@Borzole
Thanks for the info. They will certailly help me to improve in future.
Would be awesome to actually integrate this into the dropbox sources directly.
ReplyDelete