Take a screenshot of the window the user clicks on and name the file the same as the window title

2010-12-19 320 words 2 mins read

Take a screenshot of the window the user clicks on and name the file the same as the window title

  <td>
    <div class="text codecolorer">
      &nbsp;sleep 4; xwd >foo.xwd; mv foo.xwd "$(dd skip=100 if=foo.xwd bs=1 count=256 2>/dev/null | egrep -ao '^[[:print:]]+' | tr / :).xwd"
    </div>
  </td>
</tr>
1

In general, this is actually not better than the “scrot -d4” command I’m listing it as an alternative to, so please don’t vote it down for that. I’m adding this command because xwd (X window dumper) comes with X11, so it is already installed on your machine, whereas scrot probably is not. I’ve found xwd handy on boxen that I don’t want to (or am not allowed to) install packages on.

NOTE: The dd junk for renaming the file is completely optional. I just did that for fun and because it’s interesting that xwd embeds the window title in its metadata. I probably should have just parsed the output from file(1) instead of cutting it out with dd(1), but this was more fun and less error prone.

NOTE2: Many programs don’t know what to do with an xwd format image file. You can convert it to something normal using NetPBM‘s xwdtopnm(1) or ImageMagick‘s convert(1). For example, this would work: “xwd | convert fd:0 foo.jpg”. Of course, if you have ImageMagick already installed, you’d probably use import(1) instead of xwd.

NOTE3: Xwd files can be viewed using the X Window UnDumper: “xwud

NOTE4: The sleep is not strictly necessary, I put it in there so that one has time to raise the window above any others before clicking on it.

* View this command to comment, vote or add to favourites * View all commands by hackerb9

commandlinefu.com

by David Winterbottom (codeinthehole.com)

URL: http://feedproxy.google.com/~r/Command-line-fu/~3/RK7WEj8ydPg/take-a-screenshot-of-the-window-the-user-clicks-on-and-name-the-file-the-same-as-the-window-title

Enhanced by Zemanta

author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it