Take a screenshot while a menu is activated in Ubuntu

If you’re running Ubuntu and want to take a screenshot using the gnome-screenshot utility, you would notice that when you press the PRINT SCREEN keyboard key while a panel or launcher menu is activated, the screen shooter does not get executed. This is a known bug due to some old Xorg issue:
https://bugs.launchpad.net/ubuntu/+source/gnome-utils/+bug/29894

Meanwhile, You can work around it by adding a delay before it gets executed. During this delay, you activate the menu you want to include in the screenshot.
Think about a more advanced screenshot utility which is SHUTTER (sudo apt-get install shutter).

Here is a comfortable solution:

1- Install Kazam
2- Install VLC media player in order to use the cvlc dummy interface command.
3- Install dconf-editor or CompizManager in order to bind the keyboard PRINT key to a custom command.
4- Create a script that will run Kazam with a custom delay if installed.

Copy/Paste the following code in a text file, and save it into your home directory and name it: screenshooter.sh

#!/bin/bash

# This script runs shutter screenshooter if installed instead of gnome-screenshot

shutterbin="/usr/bin/shutter"
cvlcbin="/usr/bin/cvlc"
sound="/usr/share/sounds/freedesktop/stereo/camera-shutter.oga"
arg="$@"

if [ -z ${arg} ]
    then delay=3
    else delay=${arg}
fi

if [ -f "${shutterbin}" ] 
    then
        if [ -f "${cvlcbin}" ]
            then shutter -f -d ${delay} & sleep ${delay} && cvlc --play-and-exit ${sound}
            else shutter -f -d ${delay}
        fi
    else gnome-screenshot
fi
exit 0

Workspace 1_001
Then, go to CompizConfig in Gnome_Compatibility/Commands and bind the PRINT command to this command:
bash ~/screenshooter.sh 3
This means, when you press the PRINT key, Kazam or gnome-screenshot will be launched within a delay of 3 seconds, the necessary time for you to activate the menu you want to printed in the screenshot.
CVLC was used just to play the camera sound the screenshot is taken. You can get rid of it if you want by modifying the script if you don’t want to install VLC.

The following is a screencast demonstarting this post.

If you have any questions or any better solutions, please post a comment.

Advertisements

One thought on “Take a screenshot while a menu is activated in Ubuntu

  1. Goutham

    Previously, I tried installing shutter but it required a command line and 2-3 seconds to start up which was frustrating for taking a mere screenshot 🙂 The PrntScr key took the whole page rather than just the portion I wanted. Now, thanks to Compiz Manager and your awesome blog post, I set the command line for PrntScr to be
    gnome-screenshot –area
    Hope others have also benefited from this. Have a nice day!

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s