Skip to content

Instantly share code, notes, and snippets.

@isage
Forked from archydragon/i3shot.pl
Created November 21, 2012 18:49
Show Gist options
  • Save isage/4126837 to your computer and use it in GitHub Desktop.
Save isage/4126837 to your computer and use it in GitHub Desktop.
Take screenshot of all active i3 workspaces
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
use JSON qw( decode_json ); # isn't default module, must be installed via CPAN or your system package manager
use Time::HiRes qw ( usleep ); # for simple delays
my $outputfile = shift || die "use $0 outputfile.png"; # getting output filename from command-line params
my $command = 'i3-msg -t get_workspaces'; # console command used to get the list of active workspaces
my $fileprefix = '/tmp/i3shot-'; # prefix for temporary screenshots
my $decoded = decode_json(`$command`);
foreach my $workspace (@{$decoded}) {
# get the name of current workspace
my $current = $workspace->{'name'};
# move there
`i3-msg workspace $current`;
# a short delay — some windows couldn't be drawn in a moment, and we get a rubbish
usleep(200000);
# and take screenshot of all the display and save it to temporary file
`import -window root ${fileprefix}${current}.png`;
}
# montage — an utility from ImageMagick to combine multiple images to a single one
# parameters' values: -geometry — we don't need neither resizes nor shifts; -tile — put all images in a single row
`montage ${fileprefix}*.png -geometry +0+0 -tile x1 ${outputfile}`;
# cleanup
`rm -f ${fileprefix}*.png`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment