LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Making screenshot of current window using Wmctrl ... (https://www.linuxquestions.org/questions/programming-9/making-screenshot-of-current-window-using-wmctrl-4175444331/)

Xeratul 01-06-2013 01:09 AM

Making screenshot of current window using Wmctrl ...
 
Hi,

I just would like to share a cool script that can be
used to A-Print to do as alt-print the screenshot
of the running application.

It can be useful if you are making a website that show few screenshots.

Regards


Code:

#/bin/sh


GR=`echo $(xprop -root | grep _NET_ACTIVE_WINDOW | tail -1 | awk '{print $5}' | sed 's/,/' | sed 's/^0x/0x0/')`
IDLINE=` wmctrl -lp | grep "$GR" `
ID=` echo "$IDLINE" | awk ' { print $1 } ' `
echo "$ID"


# active and shot current
if [ "$1" = "-c"  ]  ; then
  window="$ID"
  counter=` head -n 2 ~/.wmctrl-screenshot.id | tail -n 1`
  checkcounter=` ls -1 ~/Desktop/screenshot* `
  notify-send "$checkcounter"
  if [ "$checkcounter" = ""  ] ; then
    counter=1
  fi
  [ ! -d ~/Desktop ] && mkdir ~/Desktop
  TARGET="$HOME/Desktop/screenshot-$counter.png"
  aplay $HOME/sounds/ding1.wav  &
  import -window $window "$TARGET"
  counter=$(( $counter +1))
  echo "$window" > ~/wmctrl-screenshot.id
  echo "$counter" >> ~/wmctrl-screenshot.id
  exit
fi





# mark as selected
if [ "$1" = "-m"  ]  ; then
  windowline=` sh ~/scripts/cooldialog.sh -i-var " $( wmctrl -l )" `
  window=` echo "$windowline" | awk ' { print $1 } ' `
  wmctrl -i -a $window
  sleep 1s
  notify-send -i ~/images/notification/monitor.png "Screenshot" "$window is selected"
  echo "$window" > ~/wmctrl-screenshot.id
  echo "1" >> ~/wmctrl-screenshot.id
  exit
fi




# go to the selected
if [ "$1" = "-g"  ]  ; then
  window=` head -n 1  > ~/wmctrl-screenshot.id`
  counter=` head -n 2 ~/wmctrl-screenshot.id | tail -n 1`
  wmctrl -i -a $window
  exit
fi



# load the selected
if [ "$1" = "-s"  ]  ; then
  window=` head -n 1  > ~/wmctrl-screenshot.id`
  counter=` head -n 2 ~/wmctrl-screenshot.id | tail -n 1`

  [ ! -d ~/Desktop ] && mkdir ~/Desktop
  TARGET="$HOME/Desktop/screenshot-$counter.png"

  aplay $HOME/sounds/ding1.wav
  import -window $window "$TARGET"

  counter=$(( $counter +1))
  echo "$window" > ~/.wmctrl-screenshot.id
  echo "$counter" >> ~/wmctrl-screenshot.id
  exit
fi




# active and shot
if [ "$1" = "-a"  ]  ; then
  windowline=` sh ~/scripts/cooldialog.sh -i-var " $( wmctrl -l )" `
  window=` echo "$windowline" | awk ' { print $1 } ' `
  wmctrl -i -a $window
  sleep 1s
  aplay $HOME/sounds/ding1.wav
  import -window $window screenshot.png
fi



All times are GMT -5. The time now is 03:37 AM.