Start a program, take automatic screenshot when its GUI has instantiated, then close program

1

This is my problem: I have a shell script, where I use gitk --all . for a graphical representation of a git repository. I would like this script to run unattended, and instead of starting gitk in GUI mode where it waits for the user to close it down, I'd like to somehow:

  • Start the gitk window
  • When it has instantiated its GUI/window, take automatic screenshot of its window
  • Once the screenshot has been captured, close gitk

I would imagine, instead of calling

gitk --all .

... in my bash script, I would otherwise call something like this pseudocode:

my_scrshot_cmd --command "gitk --all ." --file myrandomfilename.png

Is this possible to do on Linux - and if so, how can I do it?

sdaau

Posted 2015-10-05T09:49:38.213

Reputation: 3 758

Answers

1

You can try to do something like this

gitk --all . &         # You run the gitk and go forward meanwhile
PidOfLastCommand=$!    # You need to remember the PID after
sleep 30s              # Change this value with the needed one... 
import screenshot.png  # From Imagemagick it saves the screenshot
kill $PidOfLastCommand # Let's we kill gitk

echo "### Just DONE ###" 

Notes:

  • It requires Imagemagick installed (for import, but you can change the command with the one you prefer).
  • You need to wait enough time in sleep ... do some test and take a cosy value (you have to be sure it did its work)

Hastur

Posted 2015-10-05T09:49:38.213

Reputation: 15 043

Many thanks for that, @Hastur - I indeed have Imagemagick, so this will do the trick for me; accepted for now... Cheers! – sdaau – 2015-10-05T11:19:22.377