Skip to content

Instantly share code, notes, and snippets.

@SergKolo
Created August 22, 2016 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SergKolo/3360107fc15351c93852dd1daa603352 to your computer and use it in GitHub Desktop.
Save SergKolo/3360107fc15351c93852dd1daa603352 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Encode;
use Net::DBus;
use diagnostics;
sub dbus_sub
{
# Reusable subroutine for calling
# dbus methods
my $bus = Net::DBus->session;
my $service = $bus->get_service($_[0]);
my $object = $service->get_object($_[1],$_[2]);
my $method = $_[3];
my $method_out = $object->$method;
return $method_out;
}
sub is_locked
{
# wrapper subroutine for
# testing whether the
# use session is locked
my $val = dbus_sub( 'com.canonical.Unity',
'/com/canonical/Unity/Session',
'com.canonical.Unity.Session',
'IsLocked'
);
return $val;
}
my $prefix = "file://";
my $lock_background = $prefix . $ARGV[0];
my $original = qx/gsettings get org.gnome.desktop.background picture-uri /;
my @set_new=('gsettings', 'set',
'org.gnome.desktop.background', 'picture-uri',
$lock_background
);
system(@set_new);
dbus_sub( 'com.canonical.Unity',
'/com/canonical/Unity/Session',
'com.canonical.Unity.Session',
'Lock');
sleep(1);
while( is_locked() )
{
$| = 1;
print "waiting\n";
sleep(1);
}
my @restore_original = ('gsettings', 'set',
'org.gnome.desktop.background',
'picture-uri',
$original
);
system(@restore_original);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment