Created
November 21, 2012 18:37
-
-
Save archydragon/4126750 to your computer and use it in GitHub Desktop.
Take screenshot of all active i3 workspaces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
I tried debugging, and I tnink it have something to do with unicode. I changed the code to
And I'm getting
Something odd is going on, because when I'm printing the unicode characters directly, being copied from
gucharmap
into the print — I have no the error.I almost never worked with perl though, so I'm not sure of its corner cases. For the record, my workspaces code in i3/config is: