<?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/"
	>

<channel>
	<title>@ fake&#039;s &#187; bash</title>
	<atom:link href="http://plind.dk/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://plind.dk</link>
	<description>customized rants from a PHP dev&#039;s viewpoint</description>
	<lastBuildDate>Wed, 11 Aug 2010 12:52:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Alarms in Ubuntu: update</title>
		<link>http://plind.dk/2010/01/11/alarms-in-ubuntu-update/</link>
		<comments>http://plind.dk/2010/01/11/alarms-in-ubuntu-update/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 11:58:57 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[alarm]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://plind.dk/?p=298</guid>
		<description><![CDATA[In Alarms in Ubuntu, I published a script that lets you set an alarm from the command line, nice and easy. One thing was lacking though: visual notification of the alarm, so if you happen to be away from the computer when the alarm sounds you&#8217;ll still see the dialog box. To achieve that I&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[<p>In <a title="Read the original post" href="http://plind.dk/2010/01/05/alarms-in-ubuntu/">Alarms in Ubuntu</a>, I published a script that lets you set an alarm from the command line, nice and easy. One thing was lacking though: visual notification of the alarm, so if you happen to be away from the computer when the alarm sounds you&#8217;ll still see the dialog box. To achieve that I&#8217;ve modified the script, added an extra one, so here&#8217;s the new and shinier alarm script.</p>
<p>First, the alarm script:</p>
<pre>#!/bin/bash
if [ "$1" = '' ]
then
    echo "No arguments for for alarm! Supply with time and optionally message
example:
    alarm 7:45
    alarm 19:59
    alarm '3pm + 3 day'
    alarm 2010-09-18
    alarm 'now + 5 minutes' 'go do ... stuff'
    "
    exit 1
else
    message="alarm time reached"
    [ "$2" = '' ] &amp;&amp; message=$2
    if `echo aplay -q /home/fake51/Downloads/gqold.wav \&amp;\&amp; ddisplay \"$message\" | at $1 2&gt;\&amp;1 &gt; /dev/null`
    then
        exit 0
    else
        echo "Setting alarm failed"
        exit 1
    fi
fi</pre>
<p>Now, the major difference to the previous script lies in the script accepting a message, setting a default message, and then using ddisplay to display a message box.<br />
Now, ddisplay is not a linux command &#8211; it&#8217;s the second part of this scripting excercise.</p>
<pre>#!/bin/bash
if [ "$1" = "" ]
then
    exit 1
else
    export DISPLAY=:0
    zenity --warning --text="$1"
    exit 0
fi</pre>
<p>This script makes use of the zenity command &#8211; which basically displays GTK+ dialogs. The &#8216;warning&#8217; option makes zenity display a normal dialog box on top of everything, while the &#8216;text&#8217; option is obviously the text to display. Hence, pass a text string to ddisplay and you&#8217;ll get a dialog box with it &#8211; and that&#8217;s what the first script does, thus playing the alarm sound and popping up a dialog box when the sound is done.<br />
The reason for adding the extra script is that &#8216;at&#8217; schedules commands to run &#8211; so putting the dialog box code in a function in the alarm script isn&#8217;t an option. One could try sticking the zenity command straight in the &#8216;echo&#8217; piped to &#8216;at&#8217;, but to run &#8216;zenity&#8217; from a script, you typically need to set a few environment variables (these are set if you run zenity straight from the command line, but not necessarily if run by cron or at). On the plus side, ddisplay can be reused for other scripts as well, simplifying them.</p>
]]></content:encoded>
			<wfw:commentRss>http://plind.dk/2010/01/11/alarms-in-ubuntu-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alarms in Ubuntu</title>
		<link>http://plind.dk/2010/01/05/alarms-in-ubuntu/</link>
		<comments>http://plind.dk/2010/01/05/alarms-in-ubuntu/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 13:26:43 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[alarm]]></category>
		<category><![CDATA[at]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://plind.dk/?p=289</guid>
		<description><![CDATA[I&#8217;ve been looking for a while for a good, easy to use, easy to install, no fuss alarm clock. Just something I can set to go off in 10 minutes. Or at 2 o&#8217;clock. Or tomorrow. I haven&#8217;t found any apps that did that in a nice and easy fashion. I have found several that [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been looking for a while for a good, easy to use, easy to install, no fuss alarm clock. Just something I can set to go off in 10 minutes. Or at 2 o&#8217;clock. Or tomorrow. I haven&#8217;t found any apps that did that in a nice and easy fashion. I have found several that would do lots of things, but none of them were easy to use and handle &#8211; almost all of them were bloated, with bad UI. So, once more, I googled, but this time I came across another solution. &#8216;Look ye to the command line!&#8217; I read. &#8216;Use the at command, Luke!&#8217; And so I issued a &#8216;man at&#8217; and quickly came upon good stuff.</p>
<p>From the man page of at:</p>
<pre>DESCRIPTION
at and batch read commands from standard input or a specified
file which are to be executed at a later time, using /bin/sh.</pre>
<p>Which, in my ears, sound awesome! You see, what you get here is close to the power of crontab, but single-use, i.e. you setup a command to run once, at a given time, and that&#8217;s it. In other words, a command that will let you set up alarms easily.</p>
<p>The next step was turning at into an actual alarm. I prefer the sound method: play something that sounds like an actual alarm, and you&#8217;ll be sure you don&#8217;t overlook the thing. You can combine with something visual too, of course, like a dialog box. For the sound, I found <a href="http://policeinterceptor.com/navysounds.htm">AUTHENTIC NAVY ALARM SOUNDS PAGE</a> which hosts a few different wave files. In particular, the general alarm (old style) works well for me. To play it, all you need to do is</p>
<pre>aplay -q sound.file</pre>
<p>Combined with at, this then becomes</p>
<pre>echo "aplay -q sound.file" | at [time]</pre>
<p>One of the beauties of at is that it will accept lots of different time inputs. So, you can do &#8216;at 7:40&#8242;, &#8216;at 3pm&#8217;, &#8216;at now + 5 minutes&#8217;, &#8216;at today + 5 days&#8217;, etc.</p>
<p>With things put together into a script, it might look like</p>
<pre>#!/bin/bash
if [ "$1" = '' ]
then
    echo "No argument for for alarm! Supply with time
example:
    alarm 7:45
    alarm 19:59
    alarm 3pm + 3 day
    alarm 2010-09-18
    "
    exit 1
else
    if `echo aplay -q /home/fake51/Downloads/gqold.wav | at $1 2&gt;\&amp;1 &gt; /dev/null`
    then
        exit 0
    else
        echo "Setting alarm failed"
        exit 1
    fi
fi</pre>
<p>Save the above script as alarm in ~/bin/, chmod to 0755 and you can then set alarms like</p>
<pre>alarm 11:40
alarm "2010-01-06 12:00"
</pre>
<pre>alarm "now + 5 minutes"</pre>
<p>Should you want to remove the alarms before they run, you can see commands set to run with atq and remove them with atrm [number]</p>
]]></content:encoded>
			<wfw:commentRss>http://plind.dk/2010/01/05/alarms-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
