LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-06-2013, 01:09 AM   #1
Xeratul
Senior Member
 
Registered: Jun 2006
Location: Debian Land
Posts: 1,325

Rep: Reputation: 83
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
wmctrl to place a window on top / bottom layer ? Xeratul Linux - General 0 05-19-2012 05:00 AM
Command line screenshot of a single window Hko Programming 2 11-09-2010 08:01 PM
LXer: Take charge of your window manager with WMCTRL and Devil's Pie LXer Syndicated Linux News 0 12-21-2007 05:30 PM
Screenshot of ENTIRE window that is particulary behind desktop edges kovas Linux - Software 2 03-20-2006 01:11 AM
Screenshot of only one window under X devilkin Linux - Software 1 02-15-2005 10:45 PM


All times are GMT -5. The time now is 01:35 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration