Oh yeah, Lookit 0.3 is out

I pushed 0.3 out to the PPA a while ago, but have yet to do much with 0.4. I’ve just committed the first change that actually changes functionality at all and it’s the beginning of a fairly big feature for 0.4, hotkey support. Currently it’s hardcoded in, but I’d like to support changing the key combinations before 0.4 goes much further. Currently <Ctrl><Shift>3 captures the entire screen and <Ctrl><Shift>4 captures an area.

Lookit 0.3 hits Beta

Just the other day, I pushed out the first beta of version 0.3 of my screenshot utility, Lookit. Just a few minutes ago, I pushed out the second.

Lookit is a tool inspired by TinyGrab for quickly uploading and sharing screenshots. This new version brings a couple of new features that the previous version lacked, in particular, compatibility with older, non-compositing window managers, and a selection rectangle to more clearly see the area of the screen that you’re selecting.

Beta 2 includes just a couple bugfixes over beta 1, which are KDE compatibility (at least the beginnings of it, I still need some testers for this) and properly saving and restoring the save directory, if you choose to not delete images after upload.

A look at Lookit 0.3

Well, maybe “look” isn’t quite the right word, there’s not a lot of GUI to look at. However, I’ve spent a large portion of the day figuring out how to get around two of the more annoying issues in the current version, specifically, non-compositing window manager support and drawing the selection rectangle.

The new solution involves grabbing the mouse directly rather than letting the input be grabbed by an invisible window. That alone improves the application dramatically by allowing it to run without a compositing manager. With some luck, this will help with multimon support as well. Drawing the rectangle requires some lower level code, though, specifically using Xlib instead of GDK.

If there’s anything that you want to see implemented in the next release, make sure it’s mentioned on the Bug Tracker.

Lookit 0.2 Released

It’s a new project, and I’m moving fast. I just pushed Lookit 0.2 to bzr as well as the Lookit PPA. Changes include support for Imgur as an upload option, a warning when using a non-compositing window manager, Ubuntu Mono icons, and a few minor bugfixes. As always, *please* report any bugs to http://bugs.launchpad.net/lookit.

EDIT: I’ve moved to github, report bugs here: http://github.com/zachtib/lookit/issues

Lookit 0.1 Released

After around two weeks of coding in my freetime, I yesterday uploaded the first public release of my screenshot utility, Lookit. Unlike my bash script, this version has a proper GUI and no longer relies on external utilities like scrot and xclip. Instead, everything is done in native Python.

EDIT: Ubuntu 10.04 packages can be found on the project’s page on Launchpad: http://launchpad.net/lookit.

Other development is done at github: http://zachtib.github.com/lookit/

Building a GUI for my screenshot uploader

Today’s project goes back to what I was working on a couple of days ago with my screenshot upload script. I’ve been building a GUI with PyGTK to manage connections to the server that hosts the screenshots. I made a lot of progress today, learning to use the new GtkBuilder libraries and also the AppIndicator framework in Ubuntu 10.04. I’m hoping to have something out in the next couple of days.

Generating Gnome Rotating Backgrounds

The version of Gnome in Ubuntu 10.04 has the ability to automatically change through a defined set of files. Unfortunately, there’s no simple way to do this via the gui (I originally assumed that you just assigned a folder to be your background) so I whipped up a quick Python script. This could probably have been done in bash, but I took the lazy way out. I’m also sure I could have used some existing XML library, but the file is fairly simple, so I just used file.write(). If any glaring errors are pointed out, or if I feel like implementing XML properly, I’m sure I’ll post a revised version sometime soon, but for now, here’s the program:

Here’s a link to the source, in case WordPress fubars Python’s indentation.

#!/usr/bin/python

import os, os.path, sys, optparse

IMG_FILETYPES = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.svg']

def gen_bg_xml(directory, duration=1795.0, transition=5.0):
    if not os.path.isdir(directory):
        print “Error: {0} is not a valid directory”.format(directory)
        sys.exit(2)

    xmlfile = os.path.join(directory, “background.xml”)
    xml = open(xmlfile, mode=’w')

    xml.write(“<background>\n”)
    xml.write(“  <starttime>\n”)
    xml.write(“    <year>2010</year>\n”)
    xml.write(“    <month>01</month>\n”)
    xml.write(“    <day>01</day>\n”)
    xml.write(“    <hour>00</hour>\n”)
    xml.write(“    <minute>00</minute>\n”)
    xml.write(“    <second>00</second>\n”)
    xml.write(“  </starttime>\n”)

    files = os.listdir(directory)
    l = files[:] # Copy the list so we have something to iterate through
    for f in l:
        name, ext = os.path.splitext(f)
        if not ext in IMG_FILETYPES:
            files.remove(f)
            continue

    for f in files:
        absf = os.path.join(directory, f)
        if not files.index(f) == 0:
            xml.write(“    <to>{0}</to>\n”.format(absf))
            xml.write(“  </transition>\n”)
        xml.write(“  <static>\n”)
        xml.write(“    <duration>{0}</duration>\n”.format(duration))
        xml.write(“    <file>{0}</file>\n”.format(absf))
        xml.write(“  </static>\n”)
        xml.write(“  <transition>\n”)
        xml.write(“    <duration>{0}</duration>\n”.format(transition))
        xml.write(“    <from>{0}</from>\n”.format(absf))
        if files.index(f) == len(files) – 1:
            xml.write(“    <to>{0}</to>\n”.format(
                      os.path.join(directory, files[0])))
            xml.write(“  </transition>\n”)
    xml.write(“</background>”)
    xml.flush()
    xml.close()

if __name__==”__main__”:
    p = optparse.OptionParser(usage=”usage: %prog [options] directory”)
    p.add_option(‘–duration’, ‘-d’, default=”1795.0″)
    p.add_option(‘–transition’, ‘-t’, default=”5.0″)
    options, arguments = p.parse_args()
    if not len(arguments) == 1:
        p.error(“incorrect number of arguments”)
    sys.exit(1)
    gen_bg_xml(arguments[0], options.duration, options.transition)

Whew, escaping all those tabs was annoying.

Fast screenshot sharing in Linux, Part 2

So, thanks to a post on twitter, I’ve found a better way to snag screenshots by using scrot instead of compiz. This doesn’t give the graphical corruption that imagemagick does while compiz is running, and has the added bonus a being able to single-click a window to grab the entire window quickly.

So, here’s my revised source:

#!/bin/bash

user=
server=
destdir=
httpstr=

filename=`scrot -s -b -e ‘echo $f’`

md5=`md5sum $filename`
if [ "$?" -ne 0 ]; then
    notify-send “Error” “Could not generate md5sum” -i error
    exit
fi

md5=${md5/ */}

scp $filename “$user@$server:$destdir${md5}.png”
if [ "$?" -ne 0 ]; then
    notify-send “Error” “Failed upload” -i error
    exit
fi

longurl=$httpstr$md5.png

shorturl=`wget http://is.gd/api.php?longurl=$longurl -O-`
if [ "$?" -ne 0 ]; then
    notify-send “Error” “Failed to shorten URL” -i error
    $shorturl=$longurl
fi

echo $shorturl | xclip -selection clipboard

notify-send “Upload Complete” $shorturl

rm $filename

Save it and bind the script to a hotkey and you should be good to go.

See the original post for the rest of the setup.

Fast screenshot sharing in Linux

When I’m using Windows or OS X, I use a utility called Tinygrab to quickly share screenshots over the internet, whether it’s via Twitter, IM, email, etc. The concept is simple: you press a key combination, select a region of your screen, and it uploads a screenshot of that area and gives you a URL for sharing. Unfortunately, they don’t (currently) support Linux, and so I decided to create my own version.

Since this was the result of an hour or two of bash scripting, it’s somewhat limited in what it can do. I’m planning on expanding it in the near future to support GUI configuration and not rely on Compiz in order to take the screenshot. Since Compiz causes some wackyness when it comes to grabbing screens, I’m using Compiz’s Screenshot plugin, which you can enable in CompizConfigSettingsManager.  By default, the shortcut is to hold Super (aka, the Windows key) and drag your mouse button to select an area to grab. You’ll need to set two options in order for my script to work. First, the directory to save the images to. I used ~/Desktop, since the script deletes the image after it has been uploaded, however you could also use something like /tmp if you like. Second, the command to be run on the screenshot after it has been saved, which is the script you see below. I saved it to ~/bin/upload_image, but again, you can call it whatever you like, just be sure to make the file executable.

The next step is to install the necessary dependencies. Since I’m reply on a few applications, you’ll have to have the following packages installed (this is on Ubuntu 10.04), but again, I’m hoping to change this in the near future: libnotify-bin and xclip.

The script also assumes you have passwordless ssh set up with your server (yes, you do need your own server for the moment, I’m hoping I can change this in future versions) You can easily do this in Ubuntu via the “Password and Encryption Keys” item under Accessories.

Now that all that is in place, it’s time for the script. You’ll notice there are a few values you need to fill in:

#!/bin/bash

user=
server=
destdir=
httpstr=

if [ ! -e $1 ]; then
    notify-send “Error” “File does not exist” -i error
    exit
fi

md5=`md5sum $1`
if [ "$?" -ne 0 ]; then
    notify-send “Error” “Could not generate md5sum” -i error
    exit
fi

md5=${md5/ */}

scp $1 “$user@$server:$destdir${md5}.png”
if [ "$?" -ne 0 ]; then
    notify-send “Error” “Failed upload” -i error
    exit
fi

longurl=$httpstr$md5.png

shorturl=`wget http://is.gd/api.php?longurl=$longurl -O-`
if [ "$?" -ne 0 ]; then
    notify-send “Error” “Failed to shorten URL” -i error
    $shorturl=$longurl
fi

echo $shorturl | xclip -selection clipboard

notify-send “Upload Complete” $shorturl

rm $1

Those values that you need to fill in are:

user: your username on the server

server: the address of the server you’re uploading your images to

destdir: a directory on that server that’s accessible via the web, such as /var/www/screengrabs/

httpstr: the url to that directory, for example: http://www.mysite.com/screengrabs/

Once all that’s set up, try it out. Hold Super and drag your mouse to select an image on your screen. Wait a few seconds and you should either get an “Update Complete” notification, or an error with what went wrong. If the upload was a success, you’ll have a url on your clipboard shortened with is.gd, ready for the pasting.

Enjoy

Update: Bonus: Here’s how you can make use of my script without needing Compiz. I haven’t tested it yet, but it should work. You’ll need Imagemagick installed.

#!/bin/bash

import /tmp/screenshot.png

/path/to/other/script /tmp/screenshot.png

Save that and bind it to a hotkey and you should be good to go.

Building a Development Environment with VMware

Today, I decided to try and start back up with Palm webOS development (which I’m further putting off by writing this post) but before I could do that, I needed to set up my development environment. This time, rather than install it in my host operating system, which can change fairly often, I decided to create a dedicated virtual machine to do all of my webOS development in. There are a couple of advantages of this. First, my development environment remains stable and constant even when my host operating system changes or is upgrades. Secondly, I can have a 32 bit development environment when the rest of my desktop is 64 bit. This is helpful, because Palm currently only provides an i386 *.deb for the Mojo SDK, and while you can get it to work on a 64 bit system, I can avoid having to do these workarounds. Finally, it’s easy to pick up my entire development environment and take it with me from computer to computer, without having to worry about redownloading and libraries or tools on the new machine.

Since I’m using Ubuntu 9.04 x86_64 edition, most of this guide is tailored to Linux hosts, but should work fairly well on Windows or Mac hosts as well.

1. Install a Virtualization Platform

The first step was to set up my virtualization software. If you don’t already have something installed to do this, take a look at VMware Player 3.0, which is currently in the RC stages. You can get it here. Player 3 is improved over the previous versions in that it is now a fully fledged desktop virtualization product. In the past, it was only able to run virtual machines others had created, but it is now capable of creating them as well.

2. Install your Guest OS

Once you have VMware set up, you need to install your guest operating system that you will do your development on.  For my example, I chose to use Ubuntu 8.04.3 LTS, which is an older release, but is an LTS release and also the version that Palm has targeted its SDK at.  After downloading the image from http://releases.ubuntu.com/hardy/ setting up the virtual machine is very easy. All you have to do is create a new VM from Player’s UI, and give it the Ubuntu *.iso image when it asks for it. VMware will automatically set up the VM for you from there, including installing Ubuntu.

3. Set up your Environment

Next, just set up anything you need for the development you’ll be doing. In the case of Palm’s Mojo SDK, this means installing sun-java6-jre through apt, then installing the palm-sdk and palm-novacom packages from Palm’s webpage. You can also install an SDK if you prefer. I installed Eclipse 3.4.2, which was the version recommended by Palm. I then added the Palm and Aptana plugins.

4. Set up Remote Access

Finally, you can configure your virtual machine to be accessible remotely. The best way to do this (for a Linux guest) is via SSH. Install the package openssh-server in your virtual machine, then you can access it from your host through that. If you configure VMware to leave virtual machines running in the background you can close out of Player then run your IDE of choice over ssh by running something along these lines:

ssh -X user@vmipaddress /path/to/ide

which for my particular setup, winds up being:

ssh -X zach@172.16.156.129 /opt/eclipse/eclipse

You can save that command as either a bash alias or shell script, and make a launcher for it. Eclipse will then load up and run looking just like a native application, but it’s actually still keeping everything in the virtual machine, so you can still bundle up your entire environment easily.

There are some additional tricks you can do to futher integrate guest and host. One such thing that can come in handy is mounting your host’s hard drive in the guest via sshfs which will let you easily move files between guest and host.

Hopefully this will help you keep your development environment clean and stable, no matter how much you decide to tweak your host ;)