Skip to content

Instantly share code, notes, and snippets.

@archydragon
Created July 24, 2017 11:51
Show Gist options
  • Save archydragon/a6d205145776ad4a32be626b386ff3e6 to your computer and use it in GitHub Desktop.
Save archydragon/a6d205145776ad4a32be626b386ff3e6 to your computer and use it in GitHub Desktop.
i3 – screenshot of all active 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; # 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 $json = `$command`;
my $decoded = decode_json($json);
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}`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment