<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>The Junction</title>
	
	<link>http://www.ethelred.org</link>
	<description />
	<lastBuildDate>Fri, 11 Feb 2011 19:07:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/ethelred" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="ethelred" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Latest Idiotic Hack</title>
		<link>http://www.ethelred.org/articles/2011/02/01/latest-idiotic-hack/</link>
		<comments>http://www.ethelred.org/articles/2011/02/01/latest-idiotic-hack/#comments</comments>
		<pubDate>Tue, 01 Feb 2011 21:43:40 +0000</pubDate>
		<dc:creator>Edward</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[music]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.ethelred.org/?p=297</guid>
		<description><![CDATA[I run MPD to play music at home. In a burst of inspiration, today I hacked a new feature into my twitter client. If it sees a hashtag of #MPD in a tweet (or direct message), it takes the rest of the message, tries to find a song with a matching title (in my collection), [...]]]></description>
			<content:encoded><![CDATA[	<p>I run <a href="http://mpd.wikia.com/wiki/Music_Player_Daemon_Wiki">MPD</a> to play music at home.</p>

	<p>In a burst of inspiration, today I hacked a new feature into my twitter client. If it sees a hashtag of <code>#MPD</code> in a tweet (or direct message), it takes the rest of the message, tries to find a song with a matching title (in my collection), and adds it to my play queue.</p>

	<p>There&#8217;s no guarantee I&#8217;ll actually listen to them, but they&#8217;ll show up in my last.fm stream if I do&#8230;</p><img src="http://feeds.feedburner.com/~r/ethelred/~4/ogYHLG_XulY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ethelred.org/articles/2011/02/01/latest-idiotic-hack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Peppa Popper</title>
		<link>http://www.ethelred.org/articles/2010/12/06/peppa-popper/</link>
		<comments>http://www.ethelred.org/articles/2010/12/06/peppa-popper/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 11:22:52 +0000</pubDate>
		<dc:creator>Edward</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[projects]]></category>

		<guid isPermaLink="false">http://www.ethelred.org/?p=292</guid>
		<description><![CDATA[I was inspired by a children&#8217;s TV show Peppa Pig visits Daddy Pig&#8217;s Office and the fact that my daughter (aged 16 months) has been taking marginally more interest in the computer. So I did a quick hack to write a program like Mrs Cat uses in the show. It shows a white screen, and [...]]]></description>
			<content:encoded><![CDATA[	<p>I was inspired by a children&#8217;s TV show <a href="http://www.youtube.com/watch?v=H_eACUMavFQ">Peppa Pig visits Daddy Pig&#8217;s Office</a> and the fact that my daughter (aged 16 months) has been taking marginally more interest in the computer.</p>

	<p>So I did a quick hack to write a program like Mrs Cat uses in the show. It shows a white screen, and when you press keys, it displays coloured shapes. In my version, the colour and shape displayed is consistent for each key, so the user can learn which key to press for a given shape.</p>

	<p>If you have Java Web Start installed, <a href="/jaws/peppapopper.jnlp">you can run it from here</a> &#8211; press &#8216;Q&#8217; to quit.</p>

	<p>Otherwise, <a href="http://svn.ordoacerbus.com/scrapbook/scrapbook/peppa/">source code is here</a> (<span class="caps">SVN</span>).</p>

	<p>Slightly to my surprise, my daughter actually seems to enjoy playing with the end result. She&#8217;s been &#8216;asking&#8217; to play it again (by miming pressing the keyboard), and when she plays it, she will press keys and point at the screen and say &#8216;ooh&#8217;.</p><img src="http://feeds.feedburner.com/~r/ethelred/~4/GjmD9949gAU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ethelred.org/articles/2010/12/06/peppa-popper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>testing vs. documentation</title>
		<link>http://www.ethelred.org/articles/2010/10/19/testing-vs-documentation/</link>
		<comments>http://www.ethelred.org/articles/2010/10/19/testing-vs-documentation/#comments</comments>
		<pubDate>Tue, 19 Oct 2010 16:29:47 +0000</pubDate>
		<dc:creator>Edward</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.ethelred.org/?p=289</guid>
		<description><![CDATA[I have made some progress on my automatic ipod transfer script The first step is to set Nautilus (that&#8217;s the file browser in the Gnome desktop) preferences, since it is the program which deals with automatically mounting media. So in Nautilus->Edit->Preferences->Media I set the &#8216;Media Handling&#8217; for &#8216;Music Player&#8217; to run a script of my [...]]]></description>
			<content:encoded><![CDATA[	<p>I have made some progress on my <a href="http://www.ethelred.org/articles/2010/04/19/automatic-podcast-transfer-to-ipod/">automatic ipod transfer script</a></p>

	<p>The first step is to set Nautilus (that&#8217;s the file browser in the Gnome desktop) preferences, since it is the program which deals with automatically mounting media. So in Nautilus->Edit->Preferences->Media I set the &#8216;Media Handling&#8217; for &#8216;Music Player&#8217; to run a script of my choice when the ipod is connected.</p>

	<p>The next step was finding a Python script in the python-gpod examples directory which just copies over some files to an ipod &#8211; so I copied and tweaked that. (I don&#8217;t write Python very much, but I can just about understand a short existing script).</p>

	<p>Because I&#8217;m not comfortable with Python, I wrote a Bash script to be the real driver. So it is called by Nautilus when the ipod is connected, and it finds the podcasts I want to copy over, and calls the Python script just to add them.</p>

	<p>Originally, I hardcoded the ipod mount point into the Bash script. This will be fine on my systems, but it seemed a little silly &#8211; I was convinced that Nautilus must pass the mount point somehow to the programs it starts, otherwise in general they would have trouble deciding what to do. Unfortunately I couldn&#8217;t find any documentation on how the script would be started.</p>

	<p>The alternative to reading documentation is testing and seeing what happens. So I wrote a script which just appends it&#8217;s arguments and environment variables into a file. I set this up as the program for Nautilus to run, and connected the ipod, then looked in my log file. Sure enough, the first (and only) argument to the test program was the path of the mount point. So now I can use that in my real script, and it will be a bit more flexible.</p>

	<p>Just a little reminder of a point I&#8217;ve mentioned before &#8211; writing a small test script and seeing what happens is often easier and quicker than reading documentation to find out what should happen.</p><img src="http://feeds.feedburner.com/~r/ethelred/~4/AjEuBARhRlg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ethelred.org/articles/2010/10/19/testing-vs-documentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>what’s in a name</title>
		<link>http://www.ethelred.org/articles/2010/09/01/whats-in-a-name/</link>
		<comments>http://www.ethelred.org/articles/2010/09/01/whats-in-a-name/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 14:59:42 +0000</pubDate>
		<dc:creator>Edward</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[projects]]></category>

		<guid isPermaLink="false">http://www.ethelred.org/?p=287</guid>
		<description><![CDATA[In some conversations recently, I found that some other people were interested in a little tool I have written. I started wondering about setting up a Google Code project for it, since that makes it easier to &#8216;expose&#8217; in some ways. The first hurdle is that it would need to have a unique name. I [...]]]></description>
			<content:encoded><![CDATA[	<p>In some conversations recently, I found that some other people were interested in a little tool I have written. I started wondering about setting up a Google Code project for it, since that makes it easier to &#8216;expose&#8217; in some ways.</p>

	<p>The first hurdle is that it would need to have a unique name. I don&#8217;t think &#8216;My Mail Tool&#8217; is going to cut it. Any suggestions?</p>

	<p>The benefits of Google Code are that it gives me a standardised wiki, issue tracking and subversion without much work on my part. The trade-off is that I give up control to some extent. I could set up similar things on my own web space, but I&#8217;d have to do a bit more work.</p><img src="http://feeds.feedburner.com/~r/ethelred/~4/_XCBLszZhzc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ethelred.org/articles/2010/09/01/whats-in-a-name/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>the step beyond ‘it works for me’</title>
		<link>http://www.ethelred.org/articles/2010/04/30/the-step-beyond-it-works-for-me/</link>
		<comments>http://www.ethelred.org/articles/2010/04/30/the-step-beyond-it-works-for-me/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 17:17:20 +0000</pubDate>
		<dc:creator>Edward</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.ethelred.org/?p=279</guid>
		<description><![CDATA[I wrote a new version of my command line twitter client1. It now has coloured output, which helps me read more easily. Also it grabs direct messages and tweets referring to me, as well as the regular friends updates. As with most of the personal software I write, it is some files with links into [...]]]></description>
			<content:encoded><![CDATA[	<p>I wrote a new version of my command line twitter client<sup class="footnote"><a href="#fn13682665654f2c8f7fdf068">1</a></sup>. It now has coloured output, which helps me read more easily. Also it grabs direct messages and tweets referring to me, as well as the regular friends updates.</p>

	<p>As with most of the personal software I write, it is some files with links into the right place to make it work on my system, and dependencies taken care of by virtue of my having installed them already. If someone else wanted to use it, they&#8217;d have to know what they were doing, or I&#8217;d have to provide a lot of instructions<sup class="footnote"><a href="#fn8159113904f2c8f7fe0fc9">2</a></sup>.</p>

	<p>So I started thinking about packaging &#8211; making the application simple for someone else to install. I think it&#8217;s pretty cool: so wouldn&#8217;t someone else? </p>

	<p>But packaging is tricky. At a minimum I&#8217;d have to rearrange the code I have, add some supporting files and package specification. Figuring out what all the dependencies really are might take a while. Is it worth the effort?</p>

	<p>I&#8217;d also have to decide which kind of package to use. The application is written in Ruby, so I could make it a Ruby gem. But then it would only really be installable by Ruby developers, and it&#8217;s meant to be an end-user program, not a library. Or I could package it as a <code>DEB</code> for my Linux distributions of choice, but it might be tricky taking into account the other rubygems it depends on &#8211; <a href="http://pkg-ruby-extras.alioth.debian.org/rubygems.html">as explained here, rubygems do not sit well alongside Deb packages</a> </p>

	<p>In the end, I suspect I will use the program myself, and move on to the many other projects on my to-do list &#8211; I don&#8217;t get much value out of spending my time making packages.</p>

	<p id="fn13682665654f2c8f7fdf068" class="footnote"><sup>1</sup> It&#8217;s a complete rewrite, so I&#8217;m not sure if &#8216;version&#8217; is the right word.</p>

	<p id="fn8159113904f2c8f7fe0fc9" class="footnote"><sup>2</sup> In fact, when I copied it to another of my computers, I had an unanticipated issue which I had to investigate to make it work just for myself.</p><img src="http://feeds.feedburner.com/~r/ethelred/~4/nOXHAsfioWg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ethelred.org/articles/2010/04/30/the-step-beyond-it-works-for-me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>how to loop by line in bash</title>
		<link>http://www.ethelred.org/articles/2010/04/26/how-to-loop-by-line-in-bash/</link>
		<comments>http://www.ethelred.org/articles/2010/04/26/how-to-loop-by-line-in-bash/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 17:29:14 +0000</pubDate>
		<dc:creator>Edward</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.ethelred.org/?p=277</guid>
		<description><![CDATA[ORIGIFS=$IFS; IFS=`echo -en &#34;\n\b&#34;`; for line in $&#40;cat my_list_file&#41;; do echo $line; done; IFS=$ORIGIFS]]></description>
			<content:encoded><![CDATA[


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">ORIGIFS</span>=<span style="color: #007800;">$IFS</span>; <span style="color: #007800;">IFS</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-en</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>\b&quot;</span><span style="color: #000000; font-weight: bold;">`</span>; <span style="color: #000000; font-weight: bold;">for</span> line <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> my_list_file<span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$line</span>; <span style="color: #000000; font-weight: bold;">done</span>; <span style="color: #007800;">IFS</span>=<span style="color: #007800;">$ORIGIFS</span></pre></div></div>


<img src="http://feeds.feedburner.com/~r/ethelred/~4/hdrKprtOtQo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ethelred.org/articles/2010/04/26/how-to-loop-by-line-in-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>automatic podcast transfer to ipod?</title>
		<link>http://www.ethelred.org/articles/2010/04/19/automatic-podcast-transfer-to-ipod/</link>
		<comments>http://www.ethelred.org/articles/2010/04/19/automatic-podcast-transfer-to-ipod/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 19:18:13 +0000</pubDate>
		<dc:creator>Edward</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ipod]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.ethelred.org/articles/2010/04/19/automatic-podcast-transfer-to-ipod/</guid>
		<description><![CDATA[I have an iPod and a PC. When I connect the former to the latter, I would like it to automatically copy over the most recent podcast(s) from a certain directory on the PC, onto the iPod. This should not require any user interaction after plugging in the iPod. The PC is running Ubuntu 9.10, [...]]]></description>
			<content:encoded><![CDATA[	<p>I have an iPod and a PC. When I connect the former to the latter, I would like it to automatically copy over the most recent podcast(s) from a certain directory on the PC, onto the iPod. This should not require any user interaction after plugging in the iPod.</p>

	<p>The PC is running Ubuntu 9.10, and gtkpod works with the iPod &#8211; but I&#8217;m tired of opening a file browser and dragging files over every time.</p>

	<p>Any suggestions?</p><img src="http://feeds.feedburner.com/~r/ethelred/~4/kNhZF2QBLi8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ethelred.org/articles/2010/04/19/automatic-podcast-transfer-to-ipod/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>web testing with curl</title>
		<link>http://www.ethelred.org/articles/2010/03/10/web-testing-with-curl/</link>
		<comments>http://www.ethelred.org/articles/2010/03/10/web-testing-with-curl/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 20:01:23 +0000</pubDate>
		<dc:creator>Edward</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.ethelred.org/?p=274</guid>
		<description><![CDATA[It happened again. You have an annoying bug with your Java web application, and you&#8217;re stepping through with your debugger, and&#8230; whoops! looks like you just missed an important line. You fire off the same request again, so you go back to your browser and go through the steps to that point &#8211; did I [...]]]></description>
			<content:encoded><![CDATA[	<p>It happened again. You have an annoying bug with your Java web application, and you&#8217;re stepping through with your debugger, and&#8230; whoops! looks like you just missed an important line. You fire off the same request again, so you go back to your browser and go through the steps to that point &#8211; did I mention it was an Ajax request?</p>

	<p>This is where I start using <code>curl</code>. I know that all the data my request depends on is in the combination of the <span class="caps">URL</span>, the <span class="caps">POST</span> body (maybe) and the cookies. So I can set up a single line curl command that includes all of those, and use my command line history (up arrow) to run it repeatedly, as many times as I need to fix the bug. No mousing required.</p><img src="http://feeds.feedburner.com/~r/ethelred/~4/WBbE1PavxgM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ethelred.org/articles/2010/03/10/web-testing-with-curl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>video is best enjoyed on the TV</title>
		<link>http://www.ethelred.org/articles/2010/01/29/video-is-best-enjoyed-on-the-tv/</link>
		<comments>http://www.ethelred.org/articles/2010/01/29/video-is-best-enjoyed-on-the-tv/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 15:42:46 +0000</pubDate>
		<dc:creator>Edward</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[network]]></category>

		<guid isPermaLink="false">http://www.ethelred.org/?p=270</guid>
		<description><![CDATA[We recently acquired an Asus O!Play HDP-R1. This is a small box which connects to the TV and the home network so it can play video shared over the network. Since our main source of entertainment is downloaded video, we&#8217;d been looking out for something like this for a while, and this one had the [...]]]></description>
			<content:encoded><![CDATA[	<p>We recently acquired an <a href="http://www.amazon.com/Asus-Play-HDP-R1-multimedia-receiver/dp/B002P8CMAG">Asus O!Play HDP-R1.</a> This is a small box which connects to the TV and the home network so it can play video shared over the network. Since our main source of entertainment is downloaded video, we&#8217;d been looking out for something like this for a while, and this one had the right combination of features and price. It&#8217;s nice to be able to watch things while slouched in a comfy chair instead of sitting at the PC.</p>

	<p>Like quite a few small devices these days, the box runs a version of Linux, and <a href="http://minimodding.com/">a site has sprung up</a> for people looking into how to modify the firm/software running on it. I haven&#8217;t done that myself (except for a firmware update), but I have been trying out ways to feed more content to the box.</p>

	<p>First I got it playing DVDs. It doesn&#8217;t have a <span class="caps">DVD</span> drive, but I can put a <span class="caps">DVD</span> in my PC and share it. I basically followed the instructions from <a href="http://www.networkedmediatank.com/showthread.php?tid=6498">this other forum</a> but shared the disk over Samba instead of <span class="caps">NFS</span>. It uses &#8216;dvdreadfs&#8217; so that it effectively decrypts the <span class="caps">DVD</span> and then shares the decrypted version. On the video box we just have to navigate into the right Samba share and play the first file listed in <code>video_ts</code>, and it seems to deal with the <span class="caps">DVD</span> menu etc. properly.</p>

	<p>Next we have it playing YouTube video. This is possible because the recent firmware updates added support for browsing UPnP media shares. The <a href="http://mediatomb.cc/">MediaTomb</a> media server software has the capability to share YouTube videos &#8211; but you have to build from the latest svn version for it to work. It also requires transcoding software to convert the video from flv into mpeg, which means that it probably won&#8217;t work on our file server which is a low power machine. So I built and ran MediaTomb, and changed the config to enable YouTube and point it at my YouTube user account. On the video box we browse into UPnP and YouTube appears under &#8216;Online Services&#8217;. There is quite a delay when opening YouTube videos though.</p><img src="http://feeds.feedburner.com/~r/ethelred/~4/qRRwIRX9IuU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ethelred.org/articles/2010/01/29/video-is-best-enjoyed-on-the-tv/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>random compiz wallpaper</title>
		<link>http://www.ethelred.org/articles/2010/01/21/random-compiz-wallpaper/</link>
		<comments>http://www.ethelred.org/articles/2010/01/21/random-compiz-wallpaper/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 17:06:41 +0000</pubDate>
		<dc:creator>Edward</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.ethelred.org/?p=267</guid>
		<description><![CDATA[Since I have a growing number of pictures of my baby daughter, I wanted to randomly select some to use as desktop wallpaper. I put a bunch of pictures in my &#8216;wallpaper&#8217; directory and wrote this script to deal with them. #!/usr/bin/env ruby &#160; require 'pathname' require 'dbus' &#160; $wallpaper_dir = Pathname '/home/edward/wallpapers' $screensize = [...]]]></description>
			<content:encoded><![CDATA[	<p>Since I have a growing number of pictures of my baby daughter, I wanted to randomly select some to use as desktop wallpaper. I put a bunch of pictures in my &#8216;wallpaper&#8217; directory and wrote this script to deal with them.</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'pathname'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'dbus'</span>
&nbsp;
<span style="color:#ff6633; font-weight:bold;">$wallpaper_dir</span> = <span style="color:#CC00FF; font-weight:bold;">Pathname</span> <span style="color:#996600;">'/home/edward/wallpapers'</span>
<span style="color:#ff6633; font-weight:bold;">$screensize</span> = <span style="color:#996600;">`xrandr | grep '*' | tr -s ' ' | cut -f 2 -d' '`</span>.<span style="color:#CC0066; font-weight:bold;">chomp!</span>
<span style="color:#ff6633; font-weight:bold;">$sized_wallpaper</span> = <span style="color:#ff6633; font-weight:bold;">$wallpaper_dir</span>.<span style="color:#9900CC;">join</span> <span style="color:#996600;">&quot;.resized#{$screensize}&quot;</span>
<span style="color:#ff6633; font-weight:bold;">$sized_wallpaper</span>.<span style="color:#9900CC;">mkpath</span> <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#ff6633; font-weight:bold;">$sized_wallpaper</span>.<span style="color:#9900CC;">exist</span>?
&nbsp;
<span style="color:#ff6633; font-weight:bold;">$wallpaper_dir</span>.<span style="color:#9900CC;">entries</span>.<span style="color:#CC0066; font-weight:bold;">select</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#CC0066; font-weight:bold;">p</span> = f.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span>$wallpaper_dir<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">file</span>? <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> !$sized_wallpaper.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">basename</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">exist</span>?
<span style="color:#9966CC; font-weight:bold;">end</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#CC0066; font-weight:bold;">p</span> = f.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span>$wallpaper_dir<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#996600;">`convert -geometry #{$screensize} #{p} #{$sized_wallpaper.join(p.basename)}`</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
session_bus = <span style="color:#6666ff; font-weight:bold;">DBus::SessionBus</span>.<span style="color:#9900CC;">instance</span>
&nbsp;
compiz = session_bus.<span style="color:#9900CC;">service</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;org.freedesktop.compiz&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
hsize = compiz.<span style="color:#9900CC;">object</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'/org/freedesktop/compiz/core/screen0/hsize'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
hsize.<span style="color:#9900CC;">introspect</span>
ihsize = hsize<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;org.freedesktop.compiz&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
desktops = ihsize.<span style="color:#9900CC;">get</span>.<span style="color:#9900CC;">first</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> desktops
pictures = <span style="color:#ff6633; font-weight:bold;">$sized_wallpaper</span>.<span style="color:#9900CC;">entries</span>.<span style="color:#9900CC;">map</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> f.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span>$sized_wallpaper<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#CC0066; font-weight:bold;">select</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>p<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">file</span>? <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">shuffle</span>.<span style="color:#9900CC;">map</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>p<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> pictures
<span style="color:#9966CC; font-weight:bold;">if</span> pictures.<span style="color:#9900CC;">size</span> <span style="color:#006600; font-weight:bold;">&gt;</span> desktops
    pictures = pictures<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span>, desktops<span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
bgimg = compiz.<span style="color:#9900CC;">object</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'/org/freedesktop/compiz/wallpaper/screen0/bg_image'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
bgimg.<span style="color:#9900CC;">introspect</span>
ibgimg = bgimg<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;org.freedesktop.compiz&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
ibgimg.<span style="color:#9900CC;">set</span><span style="color:#006600; font-weight:bold;">&#40;</span>pictures<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>


	<p>Some notes:
	<ul>
		<li>the combination of how the ruby-dbus library and the compiz dbus interfaces work is a little clunky. I&#8217;ve started making a library to help cover up some of the weirdness here.</li>
		<li>I couldn&#8217;t find a good way to test the screen size from code, so ended up with the line which calls =xrandr= and parses its output. Not very maintainable.</li>
	</ul>
	<ul>
		<li>I was going to set up the script to run from cron every hour or so but it causes a noticeable pause on the desktop when Compiz actually swaps the pictures so I just run it occasionally.</li>
	</ul></p><img src="http://feeds.feedburner.com/~r/ethelred/~4/ChJ3cIwnniM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.ethelred.org/articles/2010/01/21/random-compiz-wallpaper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

