Saturday, January 10, 2009

Fun with Zenity

Lately I have become fairly annoyed with the amount of steps it takes to get data into my computer. Because I have become pretty interested in journaling, I have been trying to get all of my daily "stuff" into one place, and fairly organized.

This is not easy for me. I have a 2 megapixel camera phone with a 2.0 GB MicroSD card, a 4.0 megapixel digital camera with a 256 MB SD card, a GPS unit that connects via serial port, and a voice recorder on my mp3 player that saves to internal memory or MicroSD card. All of these devices are okay at what they do, but none of them are perfect for everything. Sometimes I like to just carry my phone, sometimes I just randomly blurt things into my voice recorder, and lots of times, I carry the camera and tripod for better shots.

The trouble is, I like to get all of that content into one place, according to the day it was created. It can be fairly frustrating to connect all of these things, create a folder (named by the date), and click and drag all of the content from them all into it -everyday-. I have been visualizing a script to do this sort of thing for a few weeks now, but didn't feel like committing (I get obsessive about programming, and will geek out on it if given the chance). Now that I am unemployed, I can devote a little time to it, plus I consider it a learning experience.

So, what do I need to put together? Well, I need a script that will create a folder in the space I specify, name it according to the date, create subfolders for "Images" and "GPS data", mount the various devices and cards, or confirm their presence, pull the data from them all and put them in their respective places, ask for confirmation if deleting files after moving them, and unmount the devices if needed. I also would like to specify another device if necessary, other than the ones that have previously been written into the script.

It took me about thirty minutes to bang out a pretty decent shell script to tackle this problem. I am pretty impressed with it, but it does have some hangups: first, it doesn't do any progress bars. On functions that take a minute (downloading tracks, waypoints, etc. from the GPS) it would be nice to know where we are in the process. Also, if I decided to change where I wanted the default folder to be, the script would simply throw all my stuff where it wanted without even asking me (the nerve!). Also, the script runs through all of the various devices in sequence, asking to "confirm" every step, even if a device is not there, or doesn't contain any data. When it moves data off of devices, it has no safeguard (confirm "delete"?) of the data from the device. If I accidentally entered anything but y, n or the default options, the script would blow up. Before I went any further with this (albeit a perfectly functional, but rough) script, I decided to give it a face. I also gave it a cheesy name, so I could remember the darn thing- "Grabbux" -causes it "grabs" all of my stuff for me, and puts it all into one place.

Zenity is a GTK-specific dialog-creation tool. It allows one to create dialogs and a GUI for applications, and it is pretty easy to get your head around, even if you are new to scripting/programming/Linux in general. Take a look:



On the left we have the shell script running. It works perfectly fine as it is, provided you never change the SD cards, put them in a different location, want the data to go somewhere else, etc. On the right, we have the Zenity dialog, with a much more elegant GUI. There are lot fewer clicks, and progress bars can be popped up , as well as warnings. Overall it looks better, too, and integrates much better with the Gnome desktop. It is very fast as well, but hey, this isn't exactly a heavy application or anything.

More...

0 comments: