Awesome WM Screenshot Hot Key/Shortcut in Linux

So I recently had the need for quick screenshots, at first I was thinking, a tray icon would be the best solution for my problem, but then I realized it doesn’t get better than a key press, a system wide shortcut. So what did I do? I looked to my window manager for answers, in this case Awesome WM.

First I needed a screenshot program, preferably one that could take shots from the command line. Most people use scrot, but since I had imagemagick installed, I decided to go with “import” a built-in part of imagemagick. Now, the other thing I thought about was that I needed to create a unique identifier when saving the screenshots, so if I take multiple, they don’t overwrite each other. The best way to do this would be to append the UNIX timestamp to the filename so that they all have unique filenames (this assumes you take >1 shot per second).

Now that that’s all figured out, we just have to write the functionality, so first, let’s work out the screenshot command. The parameter for “import” we’ll be needing is, -window, for the window to take the screenshot of, in this case the root window. So our command would look like this:

import -window root /home/hkothari/pictures/screens/shot-$TIME.jpg

Since Awesome is written in LUA, we’ll need to use the “os.time()” function to fetch the time, and to add the key we’re going to use awful.key, adding it in the globalkeys variable, below the comment “– Standard Programs”. So go ahead and open your “.config/awesome/rc.lua” and add the following:

-- Standard Programs
awful.key({ }, "F10", function () awful.util.spawn("import -window root /home/hkothari/pictures/screens/pic-" .. os.time() .. ".jpg") end),

This means that when the F10 key is pressed with no modifiers, it will call our screenshot function. (Note: the “..” is for concatenating strings in lua.) And that’s all there is to it.

Related posts:

  1. Using XV or Imagemagick to Set Your Background on Linux
  2. Why Samba is Awesome
  3. Syncing Your Time With The Internet (NTP) On Linux
  4. Aliasing RM to Move To Trash — Linux Recycle Bin
  5. dwm: the vim of window managers

About hkothari

I am software developer and enthusiast. I enjoy trying out new software, but prefer to use light and easy to use software. I’m currently still in high school, but working my way through it. I intern in a college computer science department, using flex and java, but I prefer C/C++, PHP and Lua. I enjoy running and swimming too. I’m a devout slackware user, but I try out a ton of other linux distros for fun and in order to learn more.
This entry was posted in Howto/Tutorial, Programming and tagged , , , , , , , , . Bookmark the permalink.

Comments are closed.

blog comments powered by Disqus