2 # ss makes a screenshot of the screen using import, and is released
3 # under the terms of the GPL version 2, or any later version, at your
4 # option. See the file README and COPYING for more information.
5 # Copyright 2004 by Don Armstrong <don@donarmstrong.com>.
18 ss - Take a screenshot of the screen, scale it, and upload it to a server
25 --host, -H host to upload image to
26 --dir, -D dir to place image (on host of -H set)
27 --import-options, -I options to import (default -window root)
28 --convert-options, -C options to convert (for scaling)
29 --scale, -s make scaled image (default)
30 --debug, -d debugging level (Default 0)
31 --help, -h display this help
32 --man, -m display manual
40 The host where the image will be uploaded to using scp
44 The local (or remote if -H used) directory to place the resultant
47 =item B<--import-options, -I>
49 The options used to invoke import. By default, -window root. (Which
50 will take a screenshot of the entire screen)
52 =item B<--convert-options, -C>
54 The options used to invoke convert, which will make a smaller image by
55 default. Only usefull if -s is set (which it is by default.)
59 If set (the default) a smaller image is made. (Technically, convert is
60 invoked with --convert-options, whether this scales depends on those
61 options.) To forgo scaling, use -s0 or --scale=0.
65 Debug verbosity. (Default 0)
69 Display brief useage information.
81 Will pretty much do what you want
85 Will take a picture of a window you select.
92 use File::Temp qw/tempfile tempdir/;
96 # XXX parse config file
98 my %options = (debug => 0,
102 dir => User->Home . '/ss',
103 import_options => '-window root',
105 convert => 'convert',
106 convert_options => '-scale 25%',
112 GetOptions(\%options,'host|H=s','import_options|I=s','file_type|t=s','scale|s!',
113 'convert_options|C=s','dir|D=s','debug|d+','help|h|?','man|m');
115 pod2usage() if $options{help};
116 pod2usage({verbose=>2}) if $options{man};
118 $DEBUG = $options{debug};
121 # XXX use perl's date command instead
122 my ($sec,$min,$hour,$mday,$mon,
123 $year,$wday,$yday,$isdst) = localtime(time);
125 my $date = qq($year).(${mon}+1).qq(${mday}_${hour}${min}${sec});
129 # use tempdir if host defined
130 if (defined $options{host}) {
131 $tempdir = $options{tempdir} || tempdir( CLEANUP => 1 );
132 print "chdir $tempdir\n" if $options{debug};
133 chdir $tempdir or die "Unable to chidr to $tempdir";
136 print "chdir $options{dir}\n" if $options{debug};
137 chdir $options{dir} or die "Unable to chdir to $options{dir}";
141 print qq($options{import} $options{import_options} ss_${date}.$options{file_type}\n) if $options{debug};
142 qx($options{import} $options{import_options} ss_${date}.$options{file_type});
146 print qq($options{convert} $options{convert_options} ss_${date}.$options{file_type} ss_${date}_small.$options{file_type}\n) if $options{scale} and $options{debug};
147 qx($options{convert} $options{convert_options} ss_${date}.$options{file_type} ss_${date}_small.$options{file_type}) if $options{scale};
150 if (defined $options{host}) {
151 my $files = "ss_${date}.$options{file_type}";
152 $files .= " ss_${date}_small.$options{file_type}" if $options{scale};
153 print qq($options{scp} $files $options{host}:$options{dir}\n) if $options{debug};
154 qx($options{scp} $files $options{host}:$options{dir});