Silly script: Download a file from the server

Thanks to Magnus the Magnificent I got a good script working to resolve links to files in thunderbird. I sometimes get e-mails pointing to a certain file. If it is not tagged with a file:/// or if it points to a remote server I just couldn’t handle the fact that it takes a couple of milliseconds to copy and paste that into some sftp terminal…

So, I got a script going… Create a shell script in your favorite bin folder (such that the path is set up to find it):


#!/bin/sh
fileName=""
dropZone=$HOME/Desktop/dropzone
server=username@servername
cd $dropZone
while $fileName; do
fileName=`inotifywait -e create --format "%f" $dropZone`
if [ "$fileName" = "dropped text.txt" ]
then
fileCont=`cat "$fileName"`
rm "$fileName"
fileName=""
sftp $server <<EOF
get $fileCont
bye
EOF
fi
done

and yes, you need inotifywait to get it working … So, you need to hack the snippet above to resolve the servername and username and you need some folder on the Desktop (which I call dropzone). Call the script whatever you like and launch it. If you create a launcher from the desktop, you will be able to get a pop-up window to enter any password to the server if required. If you start from terminal, it will prompt you for the password there…

Now, when I get an e-mail with, say:

“Kaplah!

the file is so much here:

/some/cool/path/to/some/cool/file

Then I can just mark that text in thunderbird and drag-and-drop it on the dropzone folder, and magically (?!) the file which it is pointing to shows up in that folder…

I guess there are a couple of other ways of doing it, but at least it is a start to save those 2.3 seconds…

Advertisements

One thought on “Silly script: Download a file from the server

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s