Ever since advanced desktop effects (previously Beryl or Compiz, now Compiz Fusion) were introduced, there has been an annoying broken-ness of the default Ubuntu screenshot tool. Basically, the screenshot of a window is missing the window’s frame. This problem was reported two years ago here, and remained unfixed to date.
Ok, two years should be more than enough to find a fix for something so rudimentary. But I fully understand the voluntary nature of open source software, and things did fall thru the cracks on occasions. But then again, two years?
Update 17 November 2011:
1) The bug in Launchpad has been closed as “Fix Released” for Oneric Ocelot. Older Ubuntu versions remain unfixed.2) Ronald in comment #8 below has made many improvement to the script. Visit his webpage to download it.
The problem
In Compiz Fusion lingo, window’s frame is referred to as “Window Decoration”. You should notice all the screenshots of windows and dialogboxes I made in this blog (to date) were missing their frames. This was not because I deliberately removed them; it’s a result of this bug. For instance, here is a screenshot of the calculator, using the Ubuntu screenshot tool. You can see the screenshot is missing the window’s frame.

Note:
When I mentioned the Ubuntu screenshot tool, I meant the one you get by pressing ALT+PrtScr, or by launching the tool from:Applications > Accessories > Take Screenshot
Workarounds?
I could thinking of three ways to workaround this problem.
- Live with it.
Well, not technically a workaround, but I have been ignoring this problem. It’s not too bad that a screenshot is missing the window’s frame; having the frame looks better, but not vital to the information that needs to be conveyed. - Capture the desktop with the window in question, then manually cropping the image to include the frame.
This one is doable, but requires too much work. - Temporarily disable Compiz to take the screenshot.
The screenshot worked without this problem in Metacity. This appeared to be the simplest solution, but still a hassle.
Introducing my script
When I found out about xdotool and xwininfo (see previous post), I realised it’s possible to hack a script that workaround this problem.
For this script to work, you would need to install xdotool, imagemagick and scrot.
sudo apt-get install xdotool imagemagick scrot
Then, copy/paste the script below to a text file, and set the execution bit. That’s all!
#!/bin/bash # get window id # "plus" mouse cursor for user to select the window W_ID=`xwininfo | grep "Window id" | cut -d\ -f4` # get frame id F_ID=`xprop -id $W_ID _NET_FRAME_WINDOW | cut -d\ -f5` # get frame location F_X=`xwininfo -id $F_ID | grep "Absolute upper-left X" | cut -d\: -f2` F_Y=`xwininfo -id $F_ID | grep "Absolute upper-left Y" | cut -d\: -f2` # get frame dimension F_W=`xwininfo -id $F_ID | grep "Width" | cut -d\: -f2` F_H=`xwininfo -id $F_ID | grep "Height" | cut -d\: -f2` # bring window on top xdotool windowactivate $W_ID # take screenshot of desktop # note: import command is "broken", so use scrot instead scrot -d 1 screenshot.png # crop desktop image to selected window convert -crop "$F_W"x"$F_H"+"$F_X"+"$F_Y"! screenshot.png screenshot.png
Results
I added a panel launcher for this script, so now I simply click it when I wanted to take a window screenshot. The mouse cursor will turned to a “plus”. I then click on the window I wanted to capture, and the image file will be saved to “screenshot.png”.
Here is how the calculator actually look like with frame (I used “AgingGorilla” window border).

So from now onwards, the screenshots in this blog should look better.

Comments 8
Thanks, this is nice !
I used Ctrl+PrtScr keybinding to launch the script ^^
But if I take a new screenshot, it overwrites the previous one… Is there a way to automatically name the files “sreenshot1.png”, “screenshot2.png”… ?
Posted 23 Feb 2009 at 1:40 am ¶Also I wanted to know if it was possible to have the screenshots saved on the desktop instead of the home directory ?
hi Kaho
Thanks for reading.
I guess it should be possible to automatically append a number to the filename, to prevent it from overwriting a previous file. However, it’s troublesome enough that I would not want to implement this. Really, screenshots are not something I do frequently enough to warrant the effort.
To save the screenshot file to the desktop, simply change the three occurrences of “screenshot.png” to “~/Desktop/screenshot.png”.
Posted 23 Feb 2009 at 2:00 am ¶I was caught out by this bug recently. I was replacing the original Russian screenshots in an English help file for an application (Double Commander). I stupidly didn’t notice that the screenshots were missing the titlebars and I had created about 3/4 of them. I had to switch to metacity for the window decoration and recreate them all over again
This bug still exists in Jaunty (and I wouldn’t be surprised if it’s in Karmic too). Thanks for your fix, it will be nice to take screenshots with my fancy compiz decorations
Rod.
Posted 19 Feb 2010 at 6:28 pm ¶hi Rod
Thanks for reading.
Yeah, at this stage, there is little hope this bug will ever be fixed.
Compiz Fusion developers are going thru a rewrite to C++ in version 0.9. Meanwhile, Gnome people is busy with Gnome Shell for Gnome 3. Both sides have not had a good history of co-operating.
Posted 19 Feb 2010 at 9:14 pm ¶I tried command:
import -frame -screen screenshot.png
Not everytime, but it takes the screenshot of the window with frame for me.
Posted 13 May 2010 at 12:48 pm ¶Nice script, thank you!
I’ve taken the liberty to modify it, rather dramatically:
* a Zenity pop-up to tell user to click INSIDE desired window (in case they miss the cross-hair cursor), with a Continue? Y/N option
* detects error if user clicked title bar (frame not available) and gives pop-up error message
* extracts screenshot file name from windows title and makes screenshot-$Title.png the default output file name
* uses zenity –file-selector –save –confirm-overwrite to allow user to store image where ever they please
I may post the script on one of my websites, if I can figure out an appropriate one, but wonder if you’d like the updated script to post here?
Thanks again for your effort!
rb
Posted 15 Nov 2011 at 1:33 am ¶hi Ronald
Thanks for your update. I did not post about Ubuntu for some time; the need to capture full windows have cease to be a problem
However, you are welcome to add a link to your script and I will point my blog’s visitors to the page.
Posted 16 Nov 2011 at 8:15 pm ¶Hi again,
I’ve posted my version of this excellent script, link at my name.
Note that the link is behind a self-signed HTTPS certificate, so your browser may bring that to your attention with anything from a simple notice to setting its hair on fire (I’m looking at you, Firefox).
Also, Drupal wouldn’t let me save the attachment with a *.sh name, so I had to call it *.txt: I suggest downloading & renaming to *.sh, although simply setting it to executable (chmod +x [script-name]) should do it, regardless of file name extension.
If you try it, leave me a message via the Contact form on my site: I’d love to hear from you.
Posted 17 Nov 2011 at 5:34 am ¶Post a Comment