<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>This and that about computer stuff... &#187; Gnome</title>
	<atom:link href="http://grapz.wordpress.com/category/gnome/feed/" rel="self" type="application/rss+xml" />
	<link>http://grapz.wordpress.com</link>
	<description>Random useful stuff for the computer guys...</description>
	<lastBuildDate>Thu, 05 Mar 2009 18:04:38 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='grapz.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/7fe31eef0799d6a5c6155cd17226df0f?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>This and that about computer stuff... &#187; Gnome</title>
		<link>http://grapz.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://grapz.wordpress.com/osd.xml" title="This and that about computer stuff&#8230;" />
		<item>
		<title>Perl script to change desktop background in GNOME</title>
		<link>http://grapz.wordpress.com/2008/07/23/perl-script-to-change-desktop-background-in-gnome/</link>
		<comments>http://grapz.wordpress.com/2008/07/23/perl-script-to-change-desktop-background-in-gnome/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 05:04:24 +0000</pubDate>
		<dc:creator>grapz</dc:creator>
				<category><![CDATA[Gnome]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://grapz.wordpress.com/?p=3</guid>
		<description><![CDATA[
For some reason, I don’t like having the same background for an extended amount of time (as in, more than 15 minutes). Call me crazy, but that’s just how it is.
So when I bought my current laptop (Asus G1S), it came pre-installed with Windows Vista Ultimate, so I figured I’d give it a try. With [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grapz.wordpress.com&blog=4299919&post=3&subd=grapz&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><div class="entry">
<p>For some reason, I don’t like having the same background for an extended amount of time (as in, more than 15 minutes). Call me crazy, but that’s just how it is.</p>
<p>So when I bought my current laptop (Asus G1S), it came pre-installed with Windows Vista Ultimate, so I figured I’d give it a try. With the sidebar thing I found an widget that changed my desktop background every 15 minutes or whatever I liked. Hmm, cool enough, but I don’t like that sidebar, and for some reason Win Vista always seem to run awfully slow on my computers (maybe it’s just me abusing them).</p>
<p>Anyways, after a few days, I’ve had enough with Vista. So I decided to give good old Win XP SP2 a try on this brand new baby. After an install, things are flying like crazy, but nothing is changing my desktop background :\</p>
<p>After some checking around, it seems that in a vanilla XP, it ain’t possible to change the desktop background by command line or even by API as far as I found. So I was stuck changing it manually.</p>
<p>A few weeks ago, I’d had enough of Windows XP (as I always do after a little while). I downloaded Ubunty Hardy, installed it, and always I was happy when I saw the comforting GNOME desktop. Ahhh.</p>
<p>But still, my background isn’t changing by itself <img class="wp-smiley" src="http://blog.grapz.net/wp-includes/images/smilies/icon_surprised.gif" alt="o" /> Must fix.<br />
The “easy” solution (atleast in my head), write a perl script that manages it for me.</p>
<p>My starting point was this:</p>
<ul>
<li>All my wallpapers are in one folder.</li>
<li>Not all images matches my desktop resolution.</li>
<li>I don’t really wanna think about what resolution I’m running, I want the script to figure it out themself.</li>
</ul>
<p>So, this is what I ended up with:</p>
<p>You need Image:Size to be able to use this script. If you&#8217;re running Ubuntu, just do:<br />
sudo apt-get install libimage-size-perl</p>
<blockquote><p>
#!/usr/bin/perl<br />
use Image::Size;## Set this to 0 if you don’t want this program to do anything<br />
$go = 1;</p>
<p>## Desktop background changer for GNOME<br />
## By Anders Østhus (grapz666+perl@gmail.com)<br />
## 27-04-2008<br />
##<br />
## You are free to use and spread this code as you like<br />
## If you are spreading this code, or hacking on it for your own use<br />
## I would appreciate a e-mail about it, just so I know that someone<br />
## is actually useing it for something.<br />
##<br />
## Usage: ./wallpaper.pl /path/to/wallpapers/</p>
<p>if ($go eq 0) {<br />
  exit();<br />
}</p>
<p>## Some variable declarations<br />
@files = ();<br />
$dir = “”;<br />
$dir = @ARGV[0];<br />
$previmg = “”;<br />
$wall = “”;</p>
<p>## If you want a different background color, you can chage it here.<br />
$bgcolor1 = “#000000″;<br />
$bgcolor2 = “#000000″;</p>
<p>## Get the current image<br />
$previmg = `gconftool -g /desktop/gnome/background/picture_filename`;<br />
$wall = $previmg;</p>
<p>opendir(BIN, $dir) or die “Can’t open $dir: $!”;</p>
<p>while( defined ($file = readdir BIN) ) {<br />
  if ( $file eq “..”) {<br />
  } elsif ( $file eq “.”) {<br />
  } elsif ( $file eq “Thumbs.db”) {<br />
  } else {<br />
    push(@files, $file);<br />
  }<br />
}</p>
<p>## Find out what resolution we are running…<br />
## Current resolution ends up in $tmpres[3]<br />
$res = `/usr/bin/xrandr | grep ‘*’`;<br />
@tmpres = split(/ /, $res);<br />
@subres = split(/x/, $tmpres[3]);</p>
<p>## As long as the selected image is the same as the previous image<br />
## we select a new one<br />
while ($wall eq $previmg) {<br />
  $wall = $dir . @files[&amp;getRand];<br />
}</p>
<p>## Get the resolution of the image<br />
my ($size_x, $size_y) = Image::Size::imgsize($wall);</p>
<p>## Sets the background image<br />
$cmd = `gconftool -s /desktop/gnome/background/picture_filename “$wall” -t string`;</p>
<p>## If the image is the same resolution as the desktop, set it centered<br />
## If the image is smaller than the desktop, we keep it centered<br />
## If the image is larger than the desktop, we set it to scaled<br />
if ($subres[0] &gt; $size_x || $subres[1] &gt; $size_y) {<br />
  $cent = “centered”;<br />
}<br />
if ($subres[0] &lt; $size_x || $subres[1] &lt; $size_y) {<br />
  $cent = &#8220;scaled&#8221;;<br />
}<br />
if ($subres[0] eq $size_x &amp;&amp; $subres[1] eq $size_y) {<br />
  $cent = &#8220;centered&#8221;;<br />
}</p>
<p>## Sets scaling option and background color(s).<br />
## Also sets &#8216;draw_background&#8217; to &#8216;1&#8242;, incase something has turned it off.<br />
$cmd2 = `gconftool -s /desktop/gnome/background/picture_options $cent -t string`;<br />
$cmd3 = `gconftool -s /desktop/gnome/background/primary_color $bgcolor1 -t string`;<br />
$cmd4 = `gconftool -s /desktop/gnome/background/secondary_color $bgcolor2 -t string`;<br />
$cmd5 = `gconftool -s /desktop/gnome/background/draw_background 1 -t bool`;</p>
<p>closedir(BIN);</p>
<p>## The function that returns a random image from the image array<br />
sub getRand {<br />
  my $range = scalar(@files);<br />
  return int(rand($range));<br />
}
</p></blockquote>
<p>And then I’ve just added this line in my crontab:</p>
<blockquote><p>
*/5 * * * * /home/grapz/devel/perl/wallpaper.pl /media/sda5/wallpaper/
</p></blockquote>
<p>This makes sure that this script runs every 5 minutes, every day of the week, every week of the month, every month of the year and so on.</p></div>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/grapz.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/grapz.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/grapz.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/grapz.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/grapz.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/grapz.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/grapz.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/grapz.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/grapz.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/grapz.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/grapz.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/grapz.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grapz.wordpress.com&blog=4299919&post=3&subd=grapz&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://grapz.wordpress.com/2008/07/23/perl-script-to-change-desktop-background-in-gnome/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">grapz</media:title>
		</media:content>

		<media:content url="http://blog.grapz.net/wp-includes/images/smilies/icon_surprised.gif" medium="image">
			<media:title type="html">o</media:title>
		</media:content>
	</item>
	</channel>
</rss>