Monday, September 19, 2011

see pictures saved with gnome-screenshot in order

Using gnome-screenshot you can save screenshots of specific windows in GNU/Linux.

I don't use gnome, I have sawfish as my window manager without a desktop environment, so I just bind a key like PrintScreen to "gnome-screenshot -w" to save such screenshots.

When saving screenshots in a row, you get filenames like:
Screenshot--.png

Which will probably have some spaces.
As by default the order will be something like 1 20 21 2 3, if you want to see them in a viewer like xzgv, you won't get them in the right order.

Solution:

#solution no1, using awk:
ls |sort --field-separator="-" -k 6 -n|awk 'BEGIN {dude="";} {dude = dude " \"" $0 "\""; } END {print dude}'|xargs xzgv 

#solution no2, just using the input field separator (IFS):
ls -Q | IFS="
" sort --field-separator="-" -k 6 -n|xargs xzgv

Just adjust the -k field of sort and done!