I want to write a script that changes the window focus, and sends keyboard commands, such as print screen, and arrow keys, to the system. As in I need print screen to capture my desktop, not the script window.

I can do it manually, but it is tedious, as I have a lot of screenshots to take.

I see that I can use xdotool for this. What is the key name for print-screen? (I am away from my Linux terminal, and I can't use xev remotely) alternatively, how can I figure out the names of keys, using something besides xev?

  • please state your question – vfbsilva Nov 5 '14 at 20:11
  • Depends which OS you are on. osascript can do this easily although I'm not sure your OS has it. – DisplayName Nov 5 '14 at 20:20

No need to "invoke" the PrtSrn button, if you install ImageMagick then you can do the following in your script:

import -window root output.png

If you want a particular window you can try to find its id first with wmctrl (the following captures the Firefox window displaying this post, the grep-ed string has to be unique.):

id=$(wmctrl -l | grep -F 'bash - simulate' | cut -d ' ' -f 1)
import -window $id window.png

Alternatively, if you know the part of the screen you need is on a particular place, you can grab the whole screen and then use convert -chop to cut out what you need from the desktop image.

ImageMagick is normally installed using a package named imagemagick

  • is that python? – j0h Nov 5 '14 at 20:18
  • No that actually a command that is part of the ImageMagick suite. – Anthon Nov 5 '14 at 20:19
  • Do you know how I might specify a particular area of the screen? I just started reading the man page – j0h Nov 5 '14 at 20:23
  • How do I get the window ID? – j0h Nov 5 '14 at 20:27
  • The window ID is not so easy to get you can use wmctrl to extract it based on the window title. If the window is positioned on the same spot every time, I would grab the screen and use convert -chop to select the part you need. – Anthon Nov 5 '14 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.