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/

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.

Wacom Bamboo in Ubuntu 9.04

Today I got my Wacom Bamboo USB Tablet in from Newegg.  Installation in Jaunty was incredibly easy, I just plugged it in and the Wacom drivers were already installed and ready to go.  The corners of the tablet automatically mapped to the corners of the screen, which in some previous Ubuntu releases required a bit of editing to Xorg.conf.

I’ve really only messed with two apps so far, Gimp and Evernote.  Gimp is, of course, preinstalled in Ubuntu and allows pen input just fine, although it doesn’t automatically map the eraser to the Erase tool.

Evernote doesn’t have a native Linux version, but it runs quite well in Wine.  The only issue I’ve come across so far is that I cannot drag and drop files from Nautilus into a notebook.  My plan is to use this to handwrite notes for school, and I’ve already been typing my notes into Evernote for the last few days.  Evernote is nice because it automatically keeps your notes synced between multiple installations (for me, that’s Evernote/Wine Evernote/VistaVM and Evernote/W7) and also has a web interface for when I’m not at one of my computers.  This syncing allows me to drag files to Evernote either by opening a VM or remoting to my desktop and then they will automatically be synced back to the copy of Evernote I’m running in Wine.

Small, personal web servers

Tiny Mini-ITX web server

Tiny Mini-ITX web server

I recently helped my roommate shop for a small, personal web server.  We wound up basing it on Intel’s Atom platform, and I was amazed at how cheap it was.  The server (pictured above) came up to almost exactly $200, including shipping, and has a 1.6GHz Atom CPU, 512MB of Memory, and an 80GB hard drive.  It runs Ubuntu 8.04 Server Edition.

The motherboard is a Mini-ITX form factor board, so the whole server is pretty small.  It has a low power consumption, with the Atom CPU using only 4W of electricity.  For anyone looking to host their own web page, the Atom is a great way to do it.  So far, the box has handled everything we’ve thrown at it quite nicely.  It’s running a LAMP server to host a few personal sites.

If you’re willing to spend a bit more (close to $300 for the same specs) you can get the server down even smaller by using a slimmer case and laptop components.

With the cost of hardware dropping, I wonder if we’ll see devices like this mass marketed to the general public.  It’s mainly a matter of making a nice interface for it to easily allow setting up a photo or blog site. Imagine a desktop application that would allow a user to type up a blog post, upload photos, etc., then automatically upload that content to the server.

If anyone’s curious, the hardware we bought is here.  The motherboard is currently out of stock, however, as Intel has released a dual core version.  I’ll update the wishlist when Newegg gets the new board in.