May 26, 2009

Upload photos to facebook from Nautilus

~UPDATED 15-07-2010
Added ability to create album.
Photo's will be auto-rotated if EXIF information is available.
reworked the mechanism to work with the new FBCMD.
Does not need a manual update of albumdata file (will be handled on it's own.)

If you run this on a directory, it will upload all *.jpg files in said directory.


Fixed stupid bug where the cancelling uploaded the picture anyway.Thank you Mr. Anonymous bug reporter.

It's been a while since I've posted an update, not that I suspect that anybody missed me or anything. Nonetheless I'm throwing out an obligatory apology and the explaination for it being "been busy"

anyway this is something I whipped up today that somebody might find useful. It's a nautilus script that uploads your photos to facebook. So you can just right-click on a photo and upload it there.It's fairly basic (offers multiple uploads,album-selection, no-tagging,no caption), and once again it's not completely idiot proof so I'm not taking responsibility if you muck something up.

currently this depends on the following
  • libnotify (particularly notify-send)
  • zenity
  • imagemagick
  • fbcmd (and hence php)
fbcmd here being the facebook command-line application by Dave Tompkins, which can be found at So once you have that up and running and properly authorized (find instructions on fbcmd page)

The script needs to go into ~/.gnome2/nautilus-scripts

Next you should setup an albumid file because it's faster if you maintain a local list). Do this by running

php fbcmd.php albums | tee ~/.fbaids

if you'd rather fetch album information from facebook everytime you can replace the line "aidlist=~/.fbaids" with "aidlist=\"$(php FBCMDPATH albums)\""
that should do it.

please note that I haven't implemented a check on weather the upload was successful or not. Also there is no filetype check so be careful.

# AUTHOR: (c) Naail Abdul Rahman (
# VERSION: 1.0
# REQUIRES: libnotify, zenity, FBCMD (,imagemagick
# NAME:  Upload to Facebook
# DESCRIPTION: Simple nautilus script to invoke FBCMD upload functionality.
#  Currently only supports pictures.Hope to adding notes as well.
#  FBCMD is a command line interface to facebook by Dave Tompkins
fbcmdl=fbcmd #command to invoke fbcmd...usually just fbcmd
function notify() {
 notify-send -i fbnotif UPLOADING "$@"
function makealbum() {
 title=$(zenity --entry --title="Title?" --text="Enter Album Title (Required):")
 if [ -z $title ]
 desc=$(zenity --entry --title="Description?" \
  --text="Enter a description for the album (optional):\nLeave blank if you don't want to set a descroption")
 location=$(zenity --entry --title="Location?" \
  --text="Enter a location for the album (optional):\nLeave blank if you don't want to set a location")
 privacyOpt=$(zenity --entry --title="Privacy?" \
  --text="Who can see this album? (default:everyone)\n1.friends\n2.friends-of-friends\n3.networks\n4.everyone")
  case $privacyOpt in
   1) privacy="friends"
   2) privacy="friends-of-friends"
   3) privacy="networks"
   4) privacy="everyone"
   *) privacy="everyone"
 notify "creating album $title"
 $fbcmdl addalbum "${title}" "${desc}" "${location}" $privacy
function getaid() {
 aid=$(zenity --entry --title="Album?" \
   --text="Enter AlbumID or #\n\nenter:\n  0 for list\n  l (low L) for latest\n a for new")
 if [ -z $aid ];
  echo "null value for aid - quiting"
  notify "upload cancelled"
  case $aid in
   0) echo "please wait, fetching album data"
    $fbcmdl albums | zenity --text-info \
       --title "album names and stuff" --width=600
   l) aid="latest"
   a) makealbum
    echo "created album.."
notify "uploading photos"
for arg
 if [ -f $arg ]
  echo "adding regular file ${arg}"
  convert -auto-orient -resize '604>' "$arg" /tmp/fbuplpictmpxx.jpg
  $fbcmdl addpic /tmp/fbuplpictmpxx.jpg $aid
 elif [ -d $arg ]
  echo "uploading directory ${arg}"
  $fbcmdl addpicd $arg $aid
notify "upload finished"