Ubuntu / Linux news and application reviews.

Patrick @ Platechnotes created a simple but very useful script which automatically uploads the new images in a folder to your PicasaWeb account. The script uses GoogleCL, a tool released by Google for managing most Google services via command line.

What this script does is check a folder for new images and when you add a new image, it is instantly uploaded to your PicasaWeb account (in an album you set in the script). Note that the script will not upload any images that already exist in that folder. When an image is successfully uploaded to PicasaWeb, the script notifies you of this (using NotifyOSD) and opens the link to the image in a new web browser tab (but you can remove this behavior easily if you don't want it).


For me, there was a small error in the script so I've tweaked it a bit, however even tough I could have added checks for dependencies and so on, I didn't do that because there's no point in complicating a simple script which all these stuff - and if you follow my exact instructions below, these dependency / folder checks are not necessary.


To be able to use the script, you must follow these steps:

Don't get scared by the steps below, using the script is actually quite easy but I like explaining everything in detail.

1. Install the following packages:
sudo apt-get install inotify-tools libnotify-bin

2. Download GoogleCL and install it (it comes with .deb files)


3. Create a new file and paste the following code:

#!/bin/sh
# 1. Watch ~/Pictures/PicasaWeb folder. 
# 2. Upload new file to Picasa using Google CLI. 
# 3. Launch the browser to the direct Picasa URL. 
# 

#change the variable below with the folder you want this script to watch for new images:
WATCHED_DIR=~/Pictures/PicasaWeb

#change the variable below with exact name of the PicasaWeb album you want to upload the images to:
PICASA_ALBUM="Drop Box"

while [ 1 ]
do
  echo 'Watching directory: '$WATCHED_DIR 'for new files'
  while file=$(inotifywait -q -e create "$WATCHED_DIR" --format "%f")
  do
    echo 'New file to upload to PicasaWeb:' $file
    notify-send -i "gtk-go-up" "Picasa Web Monitor" "Uploading image $file"
    google picasa post --title $PICASA_ALBUM "$WATCHED_DIR/$file"
    url=$(google picasa list url-direct --title $PICASA_ALBUM | grep "$file" | sed -e "s/$file\,//g")
    echo 'Picasa url: ' $url
    notify-send -i "gtk-home" "Picasa Web Monitor" "Image uploaded. Launching browser."
    xdg-open $url
  done
done


Then you MUST edit the following variables in the script:
  • "WATCHED_DIR" - enter the exact path to the folder you want the script to watch (make sure the folder exists!).
  • "PICASA_ALBUM" - the PicasaWeb album to upload the images to. Make sure this album exists! Also, use an unique album name, because GoogleCL (the command line tool used to upload the images) will display display options to choose the album to upload the image to. Example: if you have 2 albums: "test" and "test 2", setting the "PICASA_ALBUM" to "test" will result in Google CL asking you if you want to upload the image to either "test" or "test 2" so the process will not be automated anymore. If you set it to upload the images to the "test 2" album, there won't be any issues (in this example).
  • Optional: by default, the script opens the link to the image in a new web browser tab. This can be disabled by commenting (add a "#" in the beginning of the line (without the quotes)) line 24 in the script (which looks like this: "xdg-open $url").

4. This step is only required once for the computer where you're using this script: GoogleCL needs the permission to upload images to your PicasaWeb account and for this, you must firstly access it from the command line so run the following command:
google picasa list

At this point, GoogleCL will request your username so enter it, then a new link will open in your web browser with the Google OAuth page - here, click the button to grant access to Google CL. Then (important!), return to the terminal where you've ran the above command and press the "ENTER" key.


5. Now save the file you've created in step 3 and make it executable (right click it, select Properties and on the Permissions tab, check the "Allow executing file as program" box).

Then run the script: either double click it and select "Run" or from a terminal. You can also add it to your startup applications.


Credits for the script: platechnotes