My Site
Categories
Awesome-wm screenshot hotkey

At Ender Labs, pretty much everyone but me uses a Mac. In the last year or so, I've started to realize that there must be some new Mac app or function that, via a hotkey, allows you to select an arbitrary region of your screen, create a screenshot, and then automatically uploads it to a hosting service. I know this, without doing any research, because in irc/slack/gtalk I've started receiving screenshots as responses to questions I ask. These screenshots arrive fairly quickly after said question is asked.

I rarely take screenshots (unless I absolutely have to), because my process involves opening gimp, going to file->create->screenshot, selecting the "select region to grab" option, setting the delay to 2 seconds so I can get the gimp window out of the way, selecting the area I want to screenshot, exporting it to a jpeg, and then uploading it to my server. It's enough hoops to jump through that I usually just try to describe what I'm seeing rather than taking a screenshot.

I liked this instant screenshot idea, and went looking for something like it for Linux. I found a few apps, but nothing were exactly what I wanted, so I decided to write my own. It's just a short, dirty python script that uses ImageMagick's import command to screenshot a region, then automatically uploads the resulting jpeg to my server, and copies the url to X's primary clipboard with xclip. The python code is below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env python

import os
import os.path
import uuid
import urlparse

fn = "/tmp/%s.jpg" % str(uuid.uuid4())
sn = os.path.basename(fn)
os.system("import %s" % fn)
os.system("notify-send \"Uploading %s\" ..." % sn)
os.system("scp %s synicworld.com:~/media/screenshots" % fn)

url = "http://synicworld.com/media/screenshots/%s" % sn

os.system("echo -n \"%s\" | xclip -selection primary" % url)

os.system("notify-send 'Copied to clipboard.'")

I saved the file to ~/bin/screenshot, made it executable, and then put the following in awesome-wm's rc.lua (keybindings section):

1
awful.key({ modkey, "Shift"   }, "s", function() awful.util.spawn("/home/synic/bin/screenshot", false) end),

Now, all I have to do is press Win+Shift+s, select a region of my screen, and the url is automatically copied to my clipboard. Neat!

Filed under: Programming, Linux
Comments:

From synic on Feb. 12 @ 11:19 a.m. 2015

test comment.
From binky on Feb. 12 @ 11:22 a.m. 2015

that's hot. I want you.

Add a comment:
captcha

Optional, for comment reply notifications
 
Note: If you enter your email address, you will be subscribed to this article and will recieve comment updates via email. This is the only thing your address will be used for. A link will be provided at the end of each email that will allow you to unsubscribe should you need to, or you can go to http://synicworld.com//unsubscribe to unsubscribe from any/all updates.