<?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>hasseg.org &#187; Mac</title>
	<atom:link href="http://hasseg.org/blog/post/category/mac/feed/" rel="self" type="application/rss+xml" />
	<link>http://hasseg.org/blog</link>
	<description></description>
	<lastBuildDate>Sun, 29 Apr 2012 09:35:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Getting Events/Tasks From the OS X Calendar Store in a Custom Format like XML, CSV or LaTeX</title>
		<link>http://hasseg.org/blog/post/602/getting-eventstasks-from-the-os-x-calendar-store-in-a-custom-format-like-xml-csv-or-latex/</link>
		<comments>http://hasseg.org/blog/post/602/getting-eventstasks-from-the-os-x-calendar-store-in-a-custom-format-like-xml-csv-or-latex/#comments</comments>
		<pubDate>Wed, 13 Oct 2010 14:49:41 +0000</pubDate>
		<dc:creator>Ali Rantakari</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://hasseg.org/blog/?p=602</guid>
		<description><![CDATA[Over the past couple of years I&#8217;ve gotten a few emails from users of icalBuddy who would like to somehow automate the task of generating CSV, XML/HTML or LaTeX output from the items in their calendar. Unfortunately icalBuddy isn&#8217;t set up to provide any kind of arbitrary output format (and I didn&#8217;t want to re-architect [...]]]></description>
			<content:encoded><![CDATA[<p>
<img src="http://hasseg.org/blog/wp-content/uploaded/2010/08/PyCalXMLCSVLaTeX.png" alt="" width="106" height="83" align="right" /> Over the past couple of years I&#8217;ve gotten a few emails from users of <a href="/icalBuddy">icalBuddy</a> who would like to somehow automate the task of generating <em>CSV</em>, <em>XML/HTML</em> or <em>LaTeX</em> output from the items in their calendar. Unfortunately icalBuddy isn&#8217;t set up to provide any kind of arbitrary output format (and I didn&#8217;t want to re-architect it to do that) but a while ago I finally had the time and motivation to figure out a small solution for this: a Python helper class for writing scripts that produce whatever type of output your heart desires.
</p>
<p><span id="more-602"></span></p>
<p>
This class is called <a href="/calStoreHelper">CalStoreHelper</a> and it provides you with <a href="/calStoreHelper/CalStoreHelper.CalStoreHelper.html">two methods</a>: one for getting events and the other for getting tasks. An <a href="/hgweb/calStoreHelper/file/tip/example.py">example script</a> shows you concretely how to generate different kinds of output. Below is a small excerpt that shows how to generate CSV output:
</p>
<div class="codecolorer-container python mac-classic codecolorer-customstyle" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">datetime</span><br />
<span style="color: #ff7700;font-weight:bold;">from</span> CalStoreHelper <span style="color: #ff7700;font-weight:bold;">import</span> *<br />
<span style="color: #ff7700;font-weight:bold;">from</span> CalendarStore <span style="color: #ff7700;font-weight:bold;">import</span> *<br />
<br />
<br />
c <span style="color: #66cc66;">=</span> CalStoreHelper<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># List of calendars to query (use None for all calendars)</span><br />
calendar_names <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: #483d8b;">'Home'</span><span style="color: #66cc66;">,</span><span style="color: #483d8b;">'Work'</span><span style="color: black;">&#93;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># Start and end dates to get events between</span><br />
start_date <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">datetime</span>.<span style="color: #dc143c;">datetime</span>.<span style="color: black;">now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
delta <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">datetime</span>.<span style="color: black;">timedelta</span><span style="color: black;">&#40;</span>days<span style="color: #66cc66;">=</span><span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span><br />
end_date <span style="color: #66cc66;">=</span> start_date + delta<br />
<br />
<span style="color: #ff7700;font-weight:bold;">def</span> example_CSV<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Example: get events + CSV formatting</span><br />
&nbsp; &nbsp; events <span style="color: #66cc66;">=</span> c.<span style="color: black;">getEvents</span><span style="color: black;">&#40;</span>calendar_names<span style="color: #66cc66;">,</span> start_date<span style="color: #66cc66;">,</span> end_date<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">from</span> UnicodeCSV <span style="color: #ff7700;font-weight:bold;">import</span> UnicodeWriter<br />
&nbsp; &nbsp; csv_writer <span style="color: #66cc66;">=</span> UnicodeWriter<span style="color: black;">&#40;</span><span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/dev/stdout'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'wb'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> event <span style="color: #ff7700;font-weight:bold;">in</span> events:<br />
&nbsp; &nbsp; &nbsp; &nbsp; csv_writer.<span style="color: black;">writerow</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event.<span style="color: #dc143c;">calendar</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">title</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event.<span style="color: black;">title</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event.<span style="color: black;">location</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event.<span style="color: black;">startDate</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">descriptionWithCalendarFormat_timeZone_locale_</span><span style="color: black;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">None</span><span style="color: #66cc66;">,</span> <span style="color: #008000;">None</span><span style="color: #66cc66;">,</span> <span style="color: #008000;">None</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event.<span style="color: black;">endDate</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">descriptionWithCalendarFormat_timeZone_locale_</span><span style="color: black;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">None</span><span style="color: #66cc66;">,</span> <span style="color: #008000;">None</span><span style="color: #66cc66;">,</span> <span style="color: #008000;">None</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event.<span style="color: black;">notes</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></div></div>
<p>
You can get the class by cloning the <a href="/calStoreHelper/#scmRepoInfo">version control repository</a> with <a href="http://mercurial.selenic.com/">Mercurial</a> or by downloading an archive from the <a href="/hgweb/calStoreHelper/">repository browser page</a> <em>(the bz2, zip and gz links at the top)</em>. Happy hacking.</p>
]]></content:encoded>
			<wfw:commentRss>http://hasseg.org/blog/post/602/getting-eventstasks-from-the-os-x-calendar-store-in-a-custom-format-like-xml-csv-or-latex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Display Events or Tasks on Your Desktop With icalBuddy</title>
		<link>http://hasseg.org/blog/post/503/how-to-display-events-or-tasks-on-your-desktop-with-icalbuddy/</link>
		<comments>http://hasseg.org/blog/post/503/how-to-display-events-or-tasks-on-your-desktop-with-icalbuddy/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 23:30:38 +0000</pubDate>
		<dc:creator>Ali Rantakari</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Miscallaneous]]></category>

		<guid isPermaLink="false">http://hasseg.org/blog/?p=503</guid>
		<description><![CDATA[I don&#8217;t really have any statistics about this but I&#8217;m quite sure that an overwhelming majority of the users of my icalBuddy program are using it to display calendar data on their desktop via GeekTool. Several tutorials on how to get this done have been written by different people, mainly for relatively non-technical users, which [...]]]></description>
			<content:encoded><![CDATA[<p>
<img src="http://hasseg.org/blog/wp-content/uploaded/2010/07/all-together.png" alt="icalBuddy, GeekTool, NerdTool icons" title="" width="129" height="131" align="right" /> I don&#8217;t really have any statistics about this but I&#8217;m quite sure that an overwhelming majority of the users of my <a href="/icalBuddy">icalBuddy</a> program are using it to <strong>display calendar data on their desktop</strong> via <a href="http://projects.tynsoe.org/en/geektool/">GeekTool</a>. Several tutorials on how to get this done have been written by different people, mainly for relatively non-technical users, which I think is great. The problem seems to be that many people don&#8217;t know how to configure icalBuddy to give them the kind of output they&#8217;d like and end up copy-pasting the commands from these blogs (some of these blog posts also contain <em>outdated</em> information about a bunch of things). Hopefully this short tutorial (and the <a href="/icalBuddy/examples.html">usage examples page</a>) will offer an easy way to make a more informed decision about how to get this done.
</p>
<p><span id="more-503"></span></p>
<h3>Choose Between GeekTool and NerdTool</h3>
<p>
<a href="http://projects.tynsoe.org/en/geektool/">GeekTool</a> and <a href="http://mutablecode.com/apps/nerdtool">NerdTool</a> are two programs that do the same thing: display stuff on your desktop. The choice between which one to use is up to you but allow me to give a few suggestions:
</p>
<ul>
<li><strong>If you want to change the text colors used in the display</strong>, choose NerdTool <em>(as far as I know, GeekTool can only change the default text color but not the actual colors used for &#8220;red&#8221;, &#8220;blue background&#8221;, &#8220;bright green&#8221; etc.)</em></li>
<li><strong>If you want to hack on the program yourself</strong>, choose NerdTool <em>(it&#8217;s open source)</em>.</li>
<li><strong>If you don&#8217;t care about any of the above</strong>, choose GeekTool.</li>
</ul>
<h3>Install the Apps</h3>
<p>
When you&#8217;ve chosen which one you&#8217;d like to use, <strong>download and install it</strong>. <a href="http://projects.tynsoe.org/en/geektool/">GeekTool</a> is a <em>preference pane</em> so it lives in your System Preferences, while <a href="http://mutablecode.com/apps/nerdtool">NerdTool</a> is a regular application which you drag into your Applications folder.
</p>
<p>
In order to install icalBuddy, <a href="/icalBuddy">download</a> the latest version and unzip the package by double-clicking on it. Open the unzipped folder, <strong>double-click on install.command</strong> and follow the instructions (you&#8217;ll have to press return, input your password and icalBuddy will be installed).
</p>
<h3>Figure out Your icalBuddy Configuration</h3>
<p>
So now you need to figure out what to put into the <em>command</em> field in Geek-/NerdTool. <strong>First you need to go to the <a href="/icalBuddy/examples.html">icalBuddy Usage Examples</a> page and browse through it</strong> &#8212; you might find the kind of output you&#8217;re looking for right there, in which case <strong>you can just get the command you see there</strong> <em>(note that some of the examples require you to <a href="http://hasseg.org/icalBuddy/examples.html#Getting+Started+With+Custom+Output+Formatting">add something to the configuration file</a>)</em>.
</p>
<p>
If you&#8217;d like to take some of the examples and modify the output a bit, you can fire up your Terminal.app and start experimenting with <a href="/icalBuddy/man.html">different arguments</a>. In this case the <a href="/icalBuddy/#documentation">documentation links</a> will come in handy.
</p>
<h3>Add Your icalBuddy Command into GeekTool/NerdTool</h3>
<p>
Once you have your command, you can put it into the app by creating a new &#8220;shell&#8221; entry:</p>
<ul>
<li><strong>GeekTool:</strong> Drag the &#8220;Shell&#8221; geeklet icon (see below) onto your desktop. The properties window for this entry should appear.</li>
<p><img src="http://hasseg.org/blog/wp-content/uploaded/2010/07/geektool-shell.png" alt="" title="" width="400" height="263" /></p>
<li><strong>NerdTool:</strong> Click the &#8220;plus&#8221; button (see below) and select &#8220;Shell&#8221; from the popup. A new entry is created into the list above.</li>
<p><img src="http://hasseg.org/blog/wp-content/uploaded/2010/07/nerdtool-add.png" alt="" title="" width="400" height="382" />
</ul>
</p>
<p>
You can then <strong>insert your icalBuddy command into the command field</strong> in whichever app you&#8217;re using (and set the refresh interval in order to specify how often the command should be run):
</p>
<p><img src="http://hasseg.org/blog/wp-content/uploaded/2010/07/geektool-and-nerdtool-command-fields.png" alt="" title="" width="470" height="334" /></p>
<p>
That&#8217;s it. You can then delve into the settings that both GeekTool and NerdTool offer you, like changing the colors and fonts used for the output.</p>
]]></content:encoded>
			<wfw:commentRss>http://hasseg.org/blog/post/503/how-to-display-events-or-tasks-on-your-desktop-with-icalbuddy/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Prevent iTunes websites from opening the iTunes app using GlimmerBlocker</title>
		<link>http://hasseg.org/blog/post/441/prevent-itunes-websites-from-opening-the-itunes-app-using-glimmerblocker/</link>
		<comments>http://hasseg.org/blog/post/441/prevent-itunes-websites-from-opening-the-itunes-app-using-glimmerblocker/#comments</comments>
		<pubDate>Fri, 16 Apr 2010 21:41:57 +0000</pubDate>
		<dc:creator>Ali Rantakari</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Miscallaneous]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://hasseg.org/blog/?p=441</guid>
		<description><![CDATA[A few minutes ago I clicked on an iTunes store link on a website and had to again completely lose it because of the iTunes app popping up without me asking it to. This is a common annoyance that people have found a bunch of different ways to combat, ranging from messing with the system&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>
<img align="right" src="http://hasseg.org/blog/wp-content/uploaded/2010/04/itunes-kickass.png" alt="" width="115" height="96" /> A few minutes ago I clicked on an iTunes store link on a website and had to again completely <em>lose it</em> because of the iTunes app popping up without me asking it to. This is a common annoyance that people have found a bunch of different ways to combat, ranging from messing with the system&#8217;s (or the browser&#8217;s) mapping of URL protocol handlers to rewriting parts of web pages via a browser plugin (e.g. GreaseMonkey) or a localhost web proxy (e.g. GlimmerBlocker).
</p>
<p><span id="more-441"></span></p>
<div class="note">
<strong>Note (Aug &#8217;10):</strong> Now that Safari 5 has support for extensions, installing the <a href="http://einserver.de/nomoreitunes">NoMoreiTunes extension</a> is probably a better way to do this.
</div>
<p>
I read somewhere that Safari (or the OS? or iTunes?) sometimes decides to &#8220;fix&#8221; the mappings of iTunes URL protocol handlers, forcing you to &#8220;play cat and mouse&#8221; if you decide to prevent iTunes from automagically opening up by removing it as the itms: protocol handler, so I decided that it would be best to try and fix this problem by messing with the iTunes website source via GlimmerBlocker, which I already was using for ad blocking.
</p>
<p>
I couldn&#8217;t find any straightforward directions on how to do this with GlimmerBlocker so I decided to post it here myself once I figured out how to do it. So this is how I prevented iTunes from automatically opening up whenever I open up a store link in my browser:
</p>
<ul>
<li>Open the GlimmerBlocker &#8220;filters&#8221; tab and <strong>add a new filter</strong>, as well as <strong>a new rule</strong> for this filter.</li>
<li>Select <strong>Whitelist URL, optionally modifying content</strong> as the action</li>
<li>For the <em>Host</em> section, select <strong>is</strong> as the predicate and type in <strong>itunes.apple.com</strong></li>
<li>Select <strong>ignored</strong> for both <em>Path</em> and <em>Query</em></li>
<li>Switch to the <strong>transform</strong> tab and type in the following:</li>
<div class="codecolorer-container javascript mac-classic codecolorer-customstyle" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">replace<span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/detectAndOpenItunes\(\);/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&lt;!-- detectAndOpenItunes() zapped --&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<li>Make sure the <em>Only for content-type</em> selection in the bottom-right corner of the dialog sheet is <strong>html</strong></li>
<li>Save</li>
</ul>
<p>
This seems to correctly prevent the iTunes app from opening up whenever a store website is opened, but it still allows for opening the viewed product in the stand-alone app via the <em>&#8220;View in iTunes&#8221;</em> link on the page.</p>
]]></content:encoded>
			<wfw:commentRss>http://hasseg.org/blog/post/441/prevent-itunes-websites-from-opening-the-itunes-app-using-glimmerblocker/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Trash files from the OS X command line</title>
		<link>http://hasseg.org/blog/post/406/trash-files-from-the-os-x-command-line/</link>
		<comments>http://hasseg.org/blog/post/406/trash-files-from-the-os-x-command-line/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 01:02:10 +0000</pubDate>
		<dc:creator>Ali Rantakari</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://hasseg.org/blog/?p=406</guid>
		<description><![CDATA[I spend a lot of time in the Terminal on my computer &#8212; a lot of things are just better done with a command-line interface than in the GUI. When removing files via the command-line people usually just, well, remove them (with the rm command), but this means that they&#8217;ll be eschewing the Trash, one [...]]]></description>
			<content:encoded><![CDATA[<p>
<img src="/trash/appIcon.png" alt="trash picture" align="right" width="96" height="88" /> I spend a lot of time in the Terminal on my computer &#8212; a lot of things are just better done with a command-line interface than in the GUI. When removing files via the command-line people usually just, well, <em>remove</em> them (with the <a href="http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/rm.1.html">rm</a> command), but this means that they&#8217;ll be eschewing the <a href="http://en.wikipedia.org/wiki/Trash_(computing)">Trash</a>, one of the user-friendliest things (even relatively) modern operating systems have had to offer for a long time.
</p>
<p><span id="more-406"></span></p>
<p>
It&#8217;s obvious we need a <span style="font-family:monospace;">trash</span> command that we can use instead of <span style="font-family:monospace;">rm</span> when we&#8217;re not 101% sure we need to <em>actually remove these files, like, right now</em>. Here are a couple of existing solutions I&#8217;ve found, my impressions of them, and then my version at the bottom:
</p>
<h3><a href="http://www.sveinbjorn.org/osxutils_docs">osxutils&#8217; trash</a> by Sveinbjörn Þórðarson</h3>
<p>
This is what I&#8217;ve used up until now. It&#8217;s a small Perl script that simply manually moves the specified files into the trash folder under the current user&#8217;s home directory:
</p>
<div class="codecolorer-container perl mac-classic codecolorer-customstyle" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;"># relevant code snippet:</span><br />
<span style="color: #339933;">...</span><br />
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>e <span style="color: #ff0000;">&quot;$ENV{HOME}/.Trash/$path_segs[$#path_segs]&quot;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">$path_segs</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$#path_segs</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #ff0000;">&quot; copy $cnt&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000066;">system</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;mv '$ARGV[$argnum]' '$ENV{HOME}/.Trash/$path_segs[$#path_segs]'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #339933;">...</span></div></div>
<p>
The biggest problem with this is that it moves all trashed files onto the <strong>same volume</strong> instead of using each volume&#8217;s own trash folders (this is not a good idea). It also deals with <strong>filename collisions</strong> manually, which is a bit volatile. The good thing about this is that it <strong>doesn&#8217;t follow &#8220;leaf&#8221; symbolic links</strong>, which is in my opinion the expected behaviour (what if I want to trash the link instead of its target?).
</p>
<h3><a href="http://www.dribin.org/dave/osx-trash/">osx-trash</a> by Dave Dribin</h3>
<p>
This one is a lot better. It&#8217;s a Ruby script that uses the <a href="http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ScriptingBridgeConcepts/Introduction/Introduction.html">Scripting Bridge</a> to ask Finder to perform all the actual &#8220;heavy lifting&#8221; (e.g. moving the files to the trash) which means that <strong>each volume&#8217;s own trash folders are utilized properly and filename collisions are handled in a standard way</strong>:
</p>
<div class="codecolorer-container ruby mac-classic codecolorer-customstyle" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#008000; font-style:italic;"># relevant code snippets:</span><br />
...<br />
<span style="color:#9900CC;">finder</span> = SBApplication.<span style="color:#9900CC;">applicationWithBundleIdentifier</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;com.apple.Finder&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
...<br />
<span style="color:#9900CC;">path</span> = <span style="color:#CC00FF; font-weight:bold;">Pathname</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>file<span style="color:#006600; font-weight:bold;">&#41;</span><br />
url = NSURL.<span style="color:#9900CC;">fileURLWithPath</span><span style="color:#006600; font-weight:bold;">&#40;</span>path.<span style="color:#9900CC;">realpath</span>.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
item = finder.<span style="color:#9900CC;">items</span>.<span style="color:#9900CC;">objectAtLocation</span><span style="color:#006600; font-weight:bold;">&#40;</span>url<span style="color:#006600; font-weight:bold;">&#41;</span><br />
item.<span style="color:#9900CC;">delete</span><br />
...</div></div>
<p>
It also allows you to list all the files that are currently in the trash and empty it (normally or securely). The few minor negative things are the fact that it <strong>follows leaf symbolic links</strong> and the fact that when you try to trash multiple files you don&#8217;t have access rights for, Finder will pop up an <strong>authentication dialog separately for each file</strong>.
</p>
<h3><a href="/trash">my trash</a></h3>
<p>
Due to the few things that I wanted the <span style="font-family:monospace;">trash</span> command to do differently, I wrote my own. In order to make sure that filename collisions are handled in the standard manner and that each volume&#8217;s trash folders are properly used (just like with Dave Dribin&#8217;s script) this one first tries to use the <strong>standard system API</strong> for trashing files, and if that fails due to the user not having the correct access rights, then asks Finder to trash those files (Finder can authenticate the current user as an administrator and move the files into that user&#8217;s trash &#8212; if you simply run this program as root, the files will be moved to root&#8217;s trash, which is not what we want):
</p>
<div class="codecolorer-container objc mac-classic codecolorer-customstyle" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #11740a; font-style: italic;">// relevant code snippets:</span><br />
...<br />
<span style="color: #11740a; font-style: italic;">// first try the standard API function (this should be</span><br />
<span style="color: #11740a; font-style: italic;">// the fastest way, and we get a nice status value</span><br />
<span style="color: #11740a; font-style: italic;">// as well):</span><br />
<span style="color: #11740a; font-style: italic;">// </span><br />
FSRef fsRef;<br />
FSPathMakeRefWithOptions<span style="color: #002200;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#40;</span><span style="color: #a61390;">const</span> UInt8 <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>filePath fileSystemRepresentation<span style="color: #002200;">&#93;</span>,<br />
&nbsp; &nbsp; kFSPathMakeRefDoNotFollowLeafSymlink,<br />
&nbsp; &nbsp; <span style="color: #002200;">&amp;</span>fsRef,<br />
&nbsp; &nbsp; <span style="color: #a61390;">NULL</span> <span style="color: #11740a; font-style: italic;">// Boolean *isDirectory</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#41;</span>;<br />
OSStatus ret <span style="color: #002200;">=</span> FSMoveObjectToTrashSync<span style="color: #002200;">&#40;</span><span style="color: #002200;">&amp;</span>fsRef, <span style="color: #a61390;">NULL</span>, kFSFileOperationDefaultOptions<span style="color: #002200;">&#41;</span>;<br />
...<br />
<span style="color: #11740a; font-style: italic;">// if no access rights, construct Apple event describing</span><br />
<span style="color: #11740a; font-style: italic;">// a &quot;delete all items in this list&quot; action and send it to Finder:</span><br />
<span style="color: #11740a; font-style: italic;">// </span><br />
<span style="color: #400080;">NSAppleEventDescriptor</span> <span style="color: #002200;">*</span>descr <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSAppleEventDescriptor</span><br />
&nbsp; &nbsp; descriptorWithDescriptorType<span style="color: #002200;">:</span><span style="color: #bf1d1a;">'furl'</span><br />
&nbsp; &nbsp; data<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>url absoluteString<span style="color: #002200;">&#93;</span> dataUsingEncoding<span style="color: #002200;">:</span>NSUTF8StringEncoding<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>urlListDescr insertDescriptor<span style="color: #002200;">:</span>descr atIndex<span style="color: #002200;">:</span>i<span style="color: #002200;">++</span><span style="color: #002200;">&#93;</span>;<br />
...<br />
ProcessSerialNumber finderPSN <span style="color: #002200;">=</span> getFinderPSN<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;<br />
<span style="color: #400080;">NSAppleEventDescriptor</span> <span style="color: #002200;">*</span>targetDesc <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSAppleEventDescriptor</span><br />
&nbsp; &nbsp; descriptorWithDescriptorType<span style="color: #002200;">:</span><span style="color: #bf1d1a;">'psn '</span><br />
&nbsp; &nbsp; bytes<span style="color: #002200;">:&amp;</span>finderPSN<br />
&nbsp; &nbsp; length<span style="color: #002200;">:</span><span style="color: #a61390;">sizeof</span><span style="color: #002200;">&#40;</span>finderPSN<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #400080;">NSAppleEventDescriptor</span> <span style="color: #002200;">*</span>descriptor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSAppleEventDescriptor</span><br />
&nbsp; &nbsp; appleEventWithEventClass<span style="color: #002200;">:</span><span style="color: #bf1d1a;">'core'</span><br />
&nbsp; &nbsp; eventID<span style="color: #002200;">:</span><span style="color: #bf1d1a;">'delo'</span><br />
&nbsp; &nbsp; targetDescriptor<span style="color: #002200;">:</span>targetDesc<br />
&nbsp; &nbsp; returnID<span style="color: #002200;">:</span>kAutoGenerateReturnID<br />
&nbsp; &nbsp; transactionID<span style="color: #002200;">:</span>kAnyTransactionID<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>descriptor setDescriptor<span style="color: #002200;">:</span>urlListDescr forKeyword<span style="color: #002200;">:</span><span style="color: #bf1d1a;">'----'</span><span style="color: #002200;">&#93;</span>;<br />
...<br />
AESendMessage<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>descriptor aeDesc<span style="color: #002200;">&#93;</span>, <span style="color: #002200;">&amp;</span>reply, kAEWaitReply, kAEDefaultTimeout<span style="color: #002200;">&#41;</span>;<br />
...</div></div>
<p>
The difference is that this one <strong>doesn&#8217;t follow leaf symlinks</strong>, and when deleting multiple files that you don&#8217;t have access rights for, Finder will only show <strong>one authentication dialog</strong> (I had to implement this kind of &#8220;manually&#8221; because I couldn&#8217;t find any way to accomplish it with the Scripting Bridge). I also copied the idea and implementation of emptying the trash and listing its contents via the Scripting Bridge from Dave&#8217;s script. This <span style="font-family:monospace;">trash</span> is written in (Objective-)C, <span class="info" title="yeah, I actually only used Objective-C and C because it was at first the only way I knew how to accomplish what I wanted, even though I now know this could've been done adequately with Ruby or Python as well">for all those extra milliseconds that are so goddamn important</span> when waiting for files to be trashed.
</p>
<p>
You can <a href="/trash">go through my trash here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://hasseg.org/blog/post/406/trash-files-from-the-os-x-command-line/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Print AppleScript files with color-coding in the Terminal</title>
		<link>http://hasseg.org/blog/post/392/print-applescript-files-with-color-coding-in-the-terminal/</link>
		<comments>http://hasseg.org/blog/post/392/print-applescript-files-with-color-coding-in-the-terminal/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 17:37:53 +0000</pubDate>
		<dc:creator>Ali Rantakari</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://hasseg.org/blog/?p=392</guid>
		<description><![CDATA[Even though I curse and hate its syntax, I have to admit that AppleScript certainly provides one of the nicest things OS X has to offer in comparison to other operating systems: almost-ubiquitous scripting of GUI applications (one could argue that this is not due to the AppleScript language itself, but the Open Scripting Architecture [...]]]></description>
			<content:encoded><![CDATA[<p>
<img align="right" src="/asprint/appIcon.png" alt="asprint image" width="128" height="106" style="margin-left: 5px;" /> Even though I <em>curse and hate</em> its syntax, I have to admit that AppleScript certainly provides one of the nicest things OS X has to offer in comparison to other operating systems: almost-ubiquitous scripting of GUI applications (one could argue that this is not due to the AppleScript language itself, but the <a href="http://developer.apple.com/mac/library/documentation/AppleScript/Conceptual/AppleScriptX/Concepts/osa.html">Open Scripting Architecture</a> which AppleScript is simply a language for, but that&#8217;s just semantics). Recently I&#8217;ve had to work with AppleScript files a bit more than usual while implementing <a href="/tagger">Tagger</a>&#8216;s <em>front app scripts</em> feature, and I noticed that I often wanted to <strong>print out the contents of (compiled) AppleScript files</strong> in the Terminal. The built-in command <a href="http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/osadecompile.1.html"><span style="font-family:monospace;">osadecompile</span></a> does just that: it reads in the AppleScript file, decompiles it, formats the code and nicely prints it out. I&#8217;m used to seeing my code with <strong>syntax highlighting</strong>, though, so I decided to write a small program that works similarly to <span style="font-family:monospace;">osadecompile</span> but uses ANSI escape sequences to format the output.
</p>
<p><span id="more-392"></span></p>
<p>
The <a href="http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ApplicationKit/Classes/NSAppleScript_AppKitAdditions/Reference/Reference.html#//apple_ref/occ/instm/NSAppleScript/richTextSource">Application Kit additions to the <span style="font-family:monospace;">NSAppleScript</span> class</a> provide an implementation of the syntax highlighting (which would be the hardest part in implementing something like this) and I already have the <a href="/ansiEscapeHelper"><span style="font-family:monospace;">ANSIEscapeHelper</span> class</a> that provides the translation of an <span style="font-family:monospace;">NSAttributedString</span> to an ANSI-escaped <span style="font-family:monospace;">NSString</span> (which would be the second-hardest part in implementing something like this) so writing a command-line program around these two parts was quite simple in the end. The program is called <strong><span style="font-family:monospace;">asprint</span></strong> and it has <a href="/asprint">its own page</a> on this site where you can download it.
</p>
<p>
This is what using <span style="font-family:monospace;">asprint</span> looks like:
</p>
<div align="center">
<img src="http://hasseg.org/blog/wp-content/uploaded/2010/03/asprint-screenshot.png" alt="asprint screenshot" width="445" height="592" />
</div></p>
]]></content:encoded>
			<wfw:commentRss>http://hasseg.org/blog/post/392/print-applescript-files-with-color-coding-in-the-terminal/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>My Custom GeekTool 2 Build with Support for ANSI Colors, UTF-8 and Different Writing Directions</title>
		<link>http://hasseg.org/blog/post/350/my-custom-geektool-2-build-with-support-for-ansi-colors-utf-8-and-different-writing-directions/</link>
		<comments>http://hasseg.org/blog/post/350/my-custom-geektool-2-build-with-support-for-ansi-colors-utf-8-and-different-writing-directions/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 22:23:40 +0000</pubDate>
		<dc:creator>Ali Rantakari</dc:creator>
				<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://hasseg.org/blog/?p=350</guid>
		<description><![CDATA[A year ago I released version 1.0.8 of my icalBuddy command-line application that I initially wrote as a way to get nicely formatted lists of my events and tasks from the OS X calendar store on top of my desktop background picture using GeekTool. This particular version was notable in my mind because it introduced [...]]]></description>
			<content:encoded><![CDATA[<p>
<img align="right" src="http://hasseg.org/blog/wp-content/uploaded/2009/07/GeekTool-hasseg-logos.png" alt="GeekTool-hasseg-logos" width="77" height="77" /> A year ago I released <a href="http://hasseg.org/icalBuddy/#1.0.8">version 1.0.8</a> of my <strong><a href="http://hasseg.org/icalBuddy">icalBuddy</a></strong> command-line application that I initially wrote as a way to get nicely formatted lists of my events and tasks from the OS X calendar store on top of my desktop background picture using <strong><a href="http://projects.tynsoe.org/en/geektool/">GeekTool</a></strong>. This particular version was notable in my mind because it introduced initial support for <strong>formatting the output via <a href="http://en.wikipedia.org/wiki/ANSI_escape_code">ANSI escape sequences</a></strong>. The initial formatting was static (that is, you couldn&#8217;t change it) and very simple (it only made the titles bold), but since then I&#8217;ve implemented all kinds of different customization options that can be used to specify how the output should be colored and otherwise formatted. The only problem was that <strong>GeekTool didn&#8217;t support ANSI escape sequences</strong>, which meant that instead of the nicely formatted output I wanted GeekTool would display a bunch of gibberish if I used the <span style="font-family:monospace;">-f</span> icalBuddy argument.
</p>
<p><div style="padding:4px;background:#eee;border:1px solid #ddd;">
<em><strong>Update (Sep 6, 09):</strong> Recompiled the preference pane as 32/64-bit binary with support for garbage collection so that it would not force System Preferences to restart on Snow Leopard.</em>
</div>
</p>
<p><span id="more-350"></span></p>
<p>
There was nothing on the horizon about any further additions to GeekTool (or any similar programs) that would provide the features I wanted (although <a href="http://thememymac.com/2009/geektool/geektool-three/">version 3 of GeekTool</a> seems to be in the making, and there&#8217;s also the GPL&#8217;d <a href="http://github.com/balthamos/geektool-3/">NerdTool</a> project which aims to implement a clone of v2 with some changes and fixes), but luckily Yann Bizeul, the author of GeekTool, had released the source code to it, which enabled me to put this feature (and a few others) in. As you can see from the screenshot below, I also took the liberty to rearrange the GUI a bit:
</p>
<p align="center">
<img src="http://hasseg.org/blog/wp-content/uploaded/2009/07/geektool-hasseg.org-build.png" alt="geektool-hasseg.org-build" width="450" height="326" />
</p>
<p>
I&#8217;ve been running this custom build for a few months now without any problems so I feel reasonably confident about releasing it. No open-source license has been specified for GeekTool 2.1.2 so I unfortunately won&#8217;t be releasing the source code for the changes I made. Sorry :(
</p>
<h2>Download link</h2>
<p>
First the most important part &mdash; here&#8217;s the download link:
</p>
<p><strong><a href="/stuff/geektool/GeekTool-2.2.1-unofficial-hasseg.org-build.zip">GeekTool-2.2.1-unofficial-hasseg.org-build.zip</a> (Latest version. Requires Leopard (Mac OS 10.5+))</strong> <em>(Sep 6, 2009: Recompiled the preference pane as 32/64-bit binary with support for garbage collection so that it would not force System Preferences to restart on Snow Leopard.)</em></p>
<p>
<a href="/stuff/geektool/GeekTool-2.2.0-unofficial-hasseg.org-build.zip">GeekTool-2.2.0-unofficial-hasseg.org-build.zip</a> <em>(Requires Leopard. Based on source code from version 2.1.2)</em>
</p>
<p><span style="color:#FF0000;">Disclaimer: I will most probably *not* fix bugs in this version or develop it further in any way. This is simply a temporary solution until the next official version of GeekTool comes around (if it includes these features, which I don&#8217;t know if it does), or someone else releases something similar.</span></p>
<p>
In order to install it, do the following:
</p>
<ol>
<li>Extract the files from the zip archive by double-clicking on it in Finder</li>
<li>Double-click on the <span style="font-family:monospace;">GeekTool.prefPane</span> file icon in Finder to install it</li>
<li>If you already had GeekTool installed, System Preferences will ask if you want to replace it. Select <em>&#8220;Replace&#8221;</em>, quit and restart System Preferences and open the GeekTool preference pane, verifying that the version label now says <em>&#8220;unofficial hasseg.org build.&#8221;</em></li>
<li>Unselect the <em>&#8220;Enable GeekTool&#8221;</em> checkbox in order to kill the old version&#8217;s background process, and then select it again in order to run the updated one.</li>
</ol>
<h2>Added Features</h2>
<h3>ANSI Escape Sequence Support</h3>
<p>
As said, this version includes support for ANSI escape sequences, including all the supported <span style="color:green;">foreground</span> and <span style="background-color:rgb(200,255,200);">background</span> colors (each of which you can change yourself on an entry-by-entry basis in GeekTool&#8217;s preferences), <strong>intensity</strong> (bolding) and <u>underlining</u> (both <u>single</u> and <u style="border-bottom:1px solid;">double</u>). Here&#8217;s an example of how my (customized) icalBuddy output looks in my GeekTool setup:
</p>
<p align="center">
<img src="http://hasseg.org/blog/wp-content/uploaded/2009/07/geektool-hasseg.org-build-desktop-example.png" alt="geektool-hasseg.org-build-desktop-example" width="450" height="377" />
</p>
<p>
In order to learn how to customize icalBuddy&#8217;s ANSI-formatted output, please refer to the <a href="http://hasseg.org/icalBuddy/config-man.html">icalBuddyConfig man page</a>. Also remember that you need to use the <span style="font-family:monospace;">-f</span> (or <span style="font-family:monospace;">&#8211;formatOutput</span>) argument to get formatted output in the first place.
</p>
<p>
Here&#8217;s what the new little preferences window that you can use to customize the <em>actual</em> colors used for displaying ANSI escape colors looks like:
</p>
<p><div align="center">
<img src="http://hasseg.org/blog/wp-content/uploaded/2009/07/geektool-hasseg.org-build-ansicolors.png" alt="geektool-hasseg.org-build-ansicolors" width="450" height="326" />
</div>
</p>
<p>
You can specify different colors for each GeekTool entry you have.
</p>
<h3>UTF-8 Support</h3>
<p>This version now supports UTF-8, which means that unicode characters (umlauts, arabic, hebrew etc.) will display correctly (version 2 only supported ASCII).</p>
<h3>Text Writing Direction Setting</h3>
<p>
I had received word from one particular user of icalBuddy from a country where the language is written from right to left (arabic, to be precise,) who had issues with the bullet point sometimes shifting to the right side of the row instead of staying at the left. This was due to the OS X text layout algorithm trying to figure out if it should print characters in a string onto the screen from right to left or from left to right and sometimes failing due to mixtures of latin and arabic characters being on the same line. Now problems such as this can be fixed by explicitly specifying the text layout direction:
</p>
<p align="center">
<img src="http://hasseg.org/blog/wp-content/uploaded/2009/07/geektool-hasseg.org-build-textdirection.png" alt="geektool-hasseg.org-build-textdirection" width="450" height="326" /></p>
]]></content:encoded>
			<wfw:commentRss>http://hasseg.org/blog/post/350/my-custom-geektool-2-build-with-support-for-ansi-colors-utf-8-and-different-writing-directions/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Quick Look Plugin/Generator for Image Folders</title>
		<link>http://hasseg.org/blog/post/292/quick-look-plugingenerator-for-image-folders/</link>
		<comments>http://hasseg.org/blog/post/292/quick-look-plugingenerator-for-image-folders/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 16:23:20 +0000</pubDate>
		<dc:creator>Ali Rantakari</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://hasseg.org/blog/?p=292</guid>
		<description><![CDATA[One of the things that I&#8217;ve always thought Windows XP did better than OS X is how it displays the thumbnails of contained images on the icons of folders that have image files inside them. I always felt this to be quite useful, but couldn&#8217;t think of any reasonable way to implement it on the [...]]]></description>
			<content:encoded><![CDATA[<p>
<img align="right" src="http://hasseg.org/blog/wp-content/uploaded/2009/03/plugin.jpg" alt="plugin" title="plugin" width="65" height="65" /> One of the things that I&#8217;ve always thought Windows XP did better than OS X is how it displays the thumbnails of contained images on the icons of folders that have image files inside them. I always felt this to be quite useful, but couldn&#8217;t think of any reasonable way to implement it on the Mac before OS X Leopard came along with its Quick Look plug-in architecture.
</p>
<p><span id="more-292"></span></p>
<p>
So I wrote a Quick Look plugin for just that. I call it <a href="/imageFolderQLGenerator/">ImageFolderQLGenerator</a> and its results, when viewed within Finder, look like this:
</p>
<div align="center">
	<img src="/imageFolderQLGenerator/example-thumbnails.png" width="457" height="186" />
</div>
<div align="center" style="margin-bottom:20px;">
	<img src="/imageFolderQLGenerator/example-preview.png" width="336" height="258" />
</div>
<p>
Implementing the plugin itself wasn&#8217;t very difficult, even for someone as inexperienced in C as me, but the biggest headache has been something that I&#8217;ve yet to find a solution to: as you can see, Finder automatically wraps folder thumbnails into these &#8220;icon decors&#8221; with their page curls and drop shadows and whatnot &#8212; I haven&#8217;t found any way to prevent this from happening. As far as I know, Finder decides if it wants to do that based on the type of the content (in this case, folders) and there&#8217;s nothing you can do to influence its choice. If someone knows a cure for this, please let me know!
</p>
<p>
You can <a href="/imageFolderQLGenerator/">download ImageFolderQLGenerator here</a>. I&#8217;ve released it under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License version 2.0</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://hasseg.org/blog/post/292/quick-look-plugingenerator-for-image-folders/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Opening a Bunch of Stuff at Once on Your Mac</title>
		<link>http://hasseg.org/blog/post/249/launching-lots-of-stuff-at-once-on-your-mac/</link>
		<comments>http://hasseg.org/blog/post/249/launching-lots-of-stuff-at-once-on-your-mac/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 18:19:53 +0000</pubDate>
		<dc:creator>Ali Rantakari</dc:creator>
				<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://hasseg.org/blog/?p=249</guid>
		<description><![CDATA[Every day when I come to work, I have a bunch of applications, files and web pages I need to open in order to get started. These are almost always the same, though with a little variation (for example, sometimes if I need to do something that requires a lot of concentration I might want [...]]]></description>
			<content:encoded><![CDATA[<p>
<img src="http://hasseg.org/blog/wp-content/uploaded/2009/02/launchlist-icon.png" alt="LaunchList application icon" width="102" height="102" align="right" /> Every day when I come to work, I have a bunch of <strong>applications, files and web pages</strong> I need to open in order to get started. These are almost always the same, though with a little variation (for example, sometimes if I need to do something that requires a lot of concentration I might want to leave <a href="http://www.adiumx.com/">Adium</a>, my instant messenger app, closed.) Now, let&#8217;s face it &#8212; opening a bunch of applications, files and web pages is <strong>not a lot of work</strong>: you just clickety-click on several icons on your Dock or Desktop, then switch to your web browser (after it&#8217;s loaded, of course) and click on some bookmarks in your bookmark bar or menu. But the problem is that <strong>I&#8217;m lazy and I hate having to do any repetitive work</strong>.
</p>
<p><span id="more-249"></span></p>
<p>
The answer, of course, is <strong>automating this process</strong>, which is very easy. You could do it with a shell script and the <a href="http://www.manpagez.com/man/1/open/">open</a> command. You could do it with AppleScript. You could write an Automator workflow. You could train a monkey to do it for you. All of these are quick and easy to set up, copy (when you want to create new &#8220;launchers&#8221; for a different set of items) and modify (with the exception of the monkey, of course,) but what is a little bit more difficult is to <strong>make it possible to pick and choose <em>at invocation time</em> which items in the list you actually want to launch</strong>, without permanently modifying the list (so for example, if I want to launch my usual list of &#8220;work&#8221; items, but this time not the IM client, while still keeping the IM client as part of the permanent list.) This was a feature I really wanted to have, so a simple script wouldn&#8217;t suffice.
</p>
<p>
What I decided to do was to create <strong>an application bundle</strong> that would store the &#8220;launch list&#8221; in a file within itself (i.e. in its &#8220;Resources&#8221; folder) so that you could make copies of this application and each one would have their own list. I would also make it possible to edit this list and launch the items via simple GUI windows. This approach would allow me to display checkboxes next to each item so that the user could easily uncheck anything they didn&#8217;t want to launch at that time. The first version of this application, which I implemented with Python, <a href="http://www.sveinbjorn.org/platypus">Platypus</a> and <a href="http://www.bluem.net/en/mac/pashua/">Pashua</a>, looked like this:
</p>
<p><img src="http://hasseg.org/blog/wp-content/uploaded/2009/02/launchlist-old.jpg" alt="Screenshot of old LaunchList version" title="Screenshot of old LaunchList version" width="500" height="446" class="size-full wp-image-253" /></p>
<p>
This worked very well &#8212; I could just create copies of this application and give each of them their own names and lists of items to launch very quickly and easily through this simple GUI. And most important: when using any of these launchers, I could quickly uncheck anything I didn&#8217;t want to launch before pressing return. But of course, being the perfectionist I am, and wanting a new idea for a small Cocoa project (so that I could teach myself a little bit more Objective-C,) I recently re-implemented the whole thing as a <strong>native OS X application</strong>. So this is what it looks like now:
</p>
<p><img src="http://hasseg.org/blog/wp-content/uploaded/2009/02/launchlist-new.jpg" alt="Screenshot of the new LaunchList version" title="Screenshot of the new LaunchList version" width="500" height="442" class="size-full wp-image-255" /></p>
<p>
I call this new version <strong>LaunchList</strong>. It&#8217;s <strong>faster, it looks nicer</strong> (see the icons? I like icons.) and it is <strong>a lot easier to use</strong>. You can use the buttons or menus in the GUI as well as keyboard shortcuts for adding, removing and reordering items, and the application tries to automatically figure out if what you typed in is an application, a file or a web address, and display an appropriate icon (or Quick Look preview.) You can also drag and drop applications, files, folders and web addresses to the main window in order to add them to the list, and have the launcher remember its size and position for the next time you use it.
</p>
<p>
I have a <a href="/launchList/">separate page</a> up for the application, where you can <a href="/launchList/#latestVersion">download the latest version</a> and check out the changelog.</p>
]]></content:encoded>
			<wfw:commentRss>http://hasseg.org/blog/post/249/launching-lots-of-stuff-at-once-on-your-mac/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Gmail Backups with fetchmail on OS X</title>
		<link>http://hasseg.org/blog/post/161/gmail-backups-with-fetchmail-on-os-x/</link>
		<comments>http://hasseg.org/blog/post/161/gmail-backups-with-fetchmail-on-os-x/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 11:32:13 +0000</pubDate>
		<dc:creator>Ali Rantakari</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://hasseg.org/blog/?p=161</guid>
		<description><![CDATA[I use GMail as my personal email provider, and as much as I like the simple and snappy UI, the conversation views and the filtering and search possibilities, I&#8217;ve grown more and more worried about having all of my (important) mails stored on someone else&#8217;s servers. Now, out of all of the big IT companies [...]]]></description>
			<content:encoded><![CDATA[<p>
<img align="right" src="http://hasseg.org/blog/wp-content/uploaded/2008/08/gmail-backup.png" alt="" title="gmail-backup" width="130" height="124" /> I use GMail as my personal email provider, and as much as I like the simple and snappy UI, the conversation views and the filtering and search possibilities, I&#8217;ve grown more and more worried about having all of my (important) mails stored on someone else&#8217;s servers. Now, out of all of the big IT companies in the world I&#8217;d say I trust Google a heck of a lot more than anyone else, but this doesn&#8217;t mean that I shouldn&#8217;t take into consideration the possibility of something going wrong on their end and as a result some (or Bob forbid, <em>all</em>) of my mails disappearing into bit heaven.
</p>
<p>
The good news is that Google provides a nice, standard POP3 interface for downloading emails from their service, and all of the software required for downloading messages via POP is already installed in Mac OS X Leopard by default. Below I&#8217;ll go through all of the steps it took me to set up periodical and automated GMail backups on my Macbook.
</p>
<p><span id="more-161"></span></p>
<p>
The following were my sources for most of the information presented here:</p>
<ul>
<li><a href="http://lifehacker.com/software/gmail/geek-to-live--back-up-gmail-with-fetchmail-235207.php">LifeHacker: Geek to Live: Back up Gmail with fetchmail</a></li>
<li><a href="http://logicbound.blogspot.com/2007/10/backup-gmail-data.html">Logic Bound: Backup Gmail Data</a></li>
<li><a href="http://bronski.net/data/fetchmail-eng.php">bronski.net: fetchmail &amp; SSL</a></li>
<li><a href="http://lists.berlios.de/pipermail/fetchmail-users/2006-July/000488.html">Matthias Andree and Paul Elliott on [fetchmail-users]: What is a &#8220;local issuer certificate&#8221;?</a></li>
</ul>
<h3>Configure GMail for POP access</h3>
<ol>
<li>Go to GMail&#8217;s <em>&#8220;Forwarding and POP/IMAP&#8221;</em> settings</li>
<li>Set the <em>&#8220;POP access&#8221;</em> setting to <strong><em>&#8220;Enable POP for all mail (even mail that&#8217;s already been downloaded)&#8221;</em></strong></li>
<li>Make sure that the <em>&#8220;When messages are accessed with POP&#8221;</em> setting says <strong><em>&#8220;keep Gmail&#8217;s copy in the inbox&#8221;</em></strong></li>
</ol>
<h3>Configure fetchmail to Download the Messages</h3>
<ol>
<li>Create <span style="font-family:monospace;">~/.fetchmailrc</span> with the following contents (replacing GMAIL_USERNAME, GMAIL_PASSWORD and LOCAL_USERNAME with their real values in your case):</li>
<pre class="prettyprint">
poll pop.gmail.com with proto POP3 and options no dns
user 'GMAIL_USERNAME@gmail.com' there with password 'GMAIL_PASSWORD' is 'LOCAL_USERNAME' here and wants mda "/usr/bin/procmail -d %T"  options ssl keep sslcertck sslcertpath "/Users/LOCAL_USERNAME/.ssl/certs"
</pre>
<p>	This configuration basically tells fetchmail to:</p>
<ul>
<li>Connect to the GMail POP server using the POP3 protocol,</li>
<li>Map your GMail username to your localhost username,</li>
<li>Deliver the downloaded mail into your local system mailbox (mail spool file),</li>
<li>Connect using an encrypted SSL connection,</li>
<li>Strictly check the SSL certificates of the server it connects to against local trusted certificates,</li>
<li>Search for the local certificates in <span style="font-family:monospace;">~/.ssl/certs</span></li>
</ul>
<li>Set the proper rights for <span style="font-family:monospace;">~/.fetchmailrc</span>:</li>
<div class="codecolorer-container text mac-classic codecolorer-customstyle" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; chmod 710 ~/.fetchmailrc</div></div>
<li>Get the pop.gmail.com server&#8217;s SSL certificate from the POP port <em>(note that this should be done using a secure, trusted internet connection &#8212; otherwise it kind of defeats the purpose)</em>:</li>
<div class="codecolorer-container text mac-classic codecolorer-customstyle" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; openssl s_client -connect pop.gmail.com:995 -showcerts</div></div>
<p>From the output of this command, copy the part that looks like this:</p>
<div class="codecolorer-container bash mac-classic codecolorer-customstyle" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #660033;">-----BEGIN</span> CERTIFICATE-----<br />
<span style="color: #7a0874; font-weight: bold;">&#40;</span>a big bunch of characters here<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #660033;">-----END</span> CERTIFICATE-----</div></div>
<p>And save it into a file called <span style="font-family:monospace;">~/.ssl/certs/gmailpop.pem</span>.</p>
<li>Download the certificate authority (Equifax) root certificate (for example <a href="http://www.geotrust.com/resources/root_certificates/index.asp">from GeoTrust&#8217;s site here</a>, where it says <em>&#8220;Equifax Secure Certificate Authority (Base-64 encoded X.509)&#8221;</em>), rename it to &#8220;equifax.pem&#8221; and move it to <span style="font-family:monospace;">~/.ssl/certs/equifax.pem</span> <em>(and just like the previous step, this should be done over a trusted internet connection as well)</em>.</li>
<li>Hash the certificates in this directory by running:</li>
<div class="codecolorer-container text mac-classic codecolorer-customstyle" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; c_rehash ~/.ssl/certs/</div></div>
</ol>
<h3>Optional: Specify the Location for Downloaded Messages</h3>
<p>
We&#8217;ve configured fetchmail to send messages to procmail, which will handle the storing of them in a <em>mail spool file</em>. By default this will be in <span style="font-family:monospace;">/var/mail/LOCAL_USERNAME</span>, but if you want to store it somewhere else, you can specify the location in the <span style="font-family:monospace;">~/.procmailrc</span> configuration file. Below is an example (replace LOCAL_USERNAME with your username):
</p>
<div class="codecolorer-container text mac-classic codecolorer-customstyle" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">MAILDIR=&quot;$HOME/.mailspool&quot;<br />
DEFAULT=&quot;$HOME/.mailspool/LOCAL_USERNAME&quot;</div></div>
<p>
I prefer to exclude my mail spool file from Time Machine backups (because it&#8217;s a large file that changes very often which makes it take up a lot of disk space from my backup volume) so I have it located in <span style="font-family:monospace;">~/.mailspool/</span> like in the above example. This is because in OS X <span style="font-family:monospace;">/var</span> is actually a symbolic link to <span style="font-family:monospace;">/private/var</span> and Time Machine has a bug where it&#8217;s impossible to exclude anything from under that path from backups (for example, if I choose to exclude <span style="font-family:monospace;">/private/var/mail</span> in the GUI, it&#8217;ll replace this selection with <span style="font-family:monospace;">/var/mail</span> automatically, and even though <span style="font-family:monospace;">/var/mail</span> is then excluded, it&#8217;ll still back up <span style="font-family:monospace;">/private/var/mail</span>).
</p>
<h3>Download Messages with fetchmail</h3>
<p>
You can now download the mail by running this command (the -v argument is for verbose output):</p>
<div class="codecolorer-container text mac-classic codecolorer-customstyle" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">fetchmail -v</div></div>
<p>Unless you only have a few mails in your Gmail box, this command will initially have to be run several times in a row in order to get all of the messages since it only downloads a few hundred messages at a time. The mail spool file containing all of the downloaded messages will then be found in <span style="font-family:monospace;">/var/mail/LOCAL_USERNAME</span> (or in whichever location you&#8217;ve specified in <span style="font-family:monospace;">~/.procmailrc</span>).
</p>
<p>
It&#8217;s a good idea to set up a launchd job for running this command between regular intervals so that you wouldn&#8217;t have to remember to manually do it yourself. <a href="http://lingon.sourceforge.net/">Lingon</a> is an ideal GUI app for this purpose. My GMail backup launchd job doesn&#8217;t call fetchmail directly, though: it calls this <a href="/stuff/gmailBackupScript/gmailBackupScript.zip">helper Python script</a> that I&#8217;ve written. The script does the following:</p>
<ul>
<li>Runs fetchmail,</li>
<li>Displays Growl messages about the result <em>(success or failure, number of messages downloaded if successful, etc.),</em></li>
<li>Optionally saves fetchmail&#8217;s output into a log file when done.</li>
</ul>
<p>Feel free to use it (remember to set the values in the &#8220;settings&#8221; section before running it, though).
</p>
<h3>Read Downloaded Messages with Thunderbird</h3>
<p>
In <a href="http://www.mozilla.com/en-US/thunderbird/">Mozilla Thunderbird</a>, go to <em>Tools > Account Settings&#8230; > Local Folders</em> to get to the <strong><em>Local directory</em></strong> path. Go into this directory and create a symbolic link there that points to the mail spool file:</p>
<div class="codecolorer-container bash mac-classic codecolorer-customstyle" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">cd</span> PATH_COPIED_FROM_THUNDERBIRD<br />
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>mail<span style="color: #000000; font-weight: bold;">/</span>LOCAL_USERNAME .<span style="color: #000000; font-weight: bold;">/</span>GMailBackups</div></div>
<p>After this you&#8217;ll be able to find your backed up GMail messages in a folder called &#8220;GMailBackups&#8221; under &#8220;Local Folders&#8221; in Thunderbird.
</p>
<div style="height:30px;">&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://hasseg.org/blog/post/161/gmail-backups-with-fetchmail-on-os-x/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>icalBuddy: Getting Events and Tasks from the OS X Calendar Store via the Command Line</title>
		<link>http://hasseg.org/blog/post/142/icalbuddy-getting-events-and-tasks-from-the-os-x-calendar-store-via-the-command-line/</link>
		<comments>http://hasseg.org/blog/post/142/icalbuddy-getting-events-and-tasks-from-the-os-x-calendar-store-via-the-command-line/#comments</comments>
		<pubDate>Thu, 19 Jun 2008 23:10:54 +0000</pubDate>
		<dc:creator>Ali Rantakari</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://hasseg.org/blog/?p=142</guid>
		<description><![CDATA[I&#8217;m a big fan of the &#8220;do not repeat yourself&#8221; principle, which, especially in the context of software, basically means that you should only have one place to change anything. Any highly volatile data that will be viewed from more than one location (or in more than one way) should only have one location and/or [...]]]></description>
			<content:encoded><![CDATA[<p>
<img src="/icalBuddy/appIcon.png" align="right" alt="icalBuddy example pic" /> I&#8217;m a big fan of the &#8220;do not repeat yourself&#8221; principle, which, especially in the context of software, basically means that you should only have one place to change anything. Any highly volatile data that will be viewed from more than one location (or in more than one way) should only have one location and/or interface for changing it. This way, whenever someone, somewhere, at some point in time happens to make changes to that data, all of the views that display it will reflect that change in true <a href="http://en.wikipedia.org/wiki/Model-view-controller">MVC</a> fashion. The <a href="http://developer.apple.com/leopard/overview/calendarstore.html">calendar store</a> in OS X is a nice centralized database for calendar data that allows me to practice this principle when it comes to my calendars, and I&#8217;ve been very happy with it, given that I&#8217;ve also gotten <a href="?p=126">automated synchronization with my cell phone to work</a>.
</p>
<p>
I used dashboard widgets for a while for getting a quick overview of all of the events I have planned for the day plus any uncompleted tasks I might have, but soon noticed that I don&#8217;t actually go and see what&#8217;s up in the dashboard very often, which lead to me forgetting some things even though I had them set up as events or tasks in my calendars. The perfect place for displaying events for the day and any uncompleted tasks for me would thus be the desktop, which, even though it is most of the time obscured by a bunch of windows, I&#8217;ll occasionally glance at during the day. <a href="http://projects.tynsoe.org/en/geektool/">GeekTool</a> is <em>the</em> solution for displaying any textual output from the shell on an OS X desktop, and I was using that already for some other things, so all that I needed was a CLI application or script that would get the events and tasks from the calendar store and output them in a nice readable way.
</p>
<p><span id="more-142"></span></p>
<p>
The only solution for this that I could find was made by some people over at <a href="http://www.macosxhints.com/article.php?story=20060918145206393">macosxhints.com</a>, who had come up with a Perl script for this purpose, but it didn&#8217;t seem very generic or reliable, so I started implementing my own version. I first tried to do it in Python, but soon ran into complexity issues with recurring events. Also, it wasn&#8217;t very fast. This was basically when I slapped myself in the head and realized that Apple has already provided <a href="http://developer.apple.com/documentation/AppleApplications/Conceptual/CalendarStoreProgGuide/Introduction/Introduction.html">a very nice API</a> in Objective-C for getting calendar items from the database and working with them. With this, I started over and managed to come up with <strong><a href="/icalBuddy/">icalBuddy</a></strong>. Here&#8217;s an example of what its output might look like (this is a list of uncompleted tasks, separated by calendar:)</p>
<div class="codecolorer-container bash mac-classic codecolorer-customstyle" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ icalBuddy <span style="color: #660033;">-sc</span> uncompletedTasks<br />
Blog stuff:<br />
<span style="color: #660033;">------------------------</span><br />
<span style="color: #000000; font-weight: bold;">*</span> Write blog post about icalBuddy<br />
&nbsp; &nbsp; notes: add some <span style="color: #c20cb9; font-weight: bold;">nice</span> pictures<br />
&nbsp; &nbsp; priority: high<br />
<br />
Home:<br />
<span style="color: #660033;">------------------------</span><br />
<span style="color: #000000; font-weight: bold;">*</span> Bask <span style="color: #000000; font-weight: bold;">in</span> your awesomeness<br />
&nbsp; &nbsp; priority: medium<br />
<span style="color: #000000; font-weight: bold;">*</span> Try not to be so great all the <span style="color: #000000; font-weight: bold;">time</span><br />
&nbsp; &nbsp; notes: People are getting jealous<br />
&nbsp; &nbsp; url: http:<span style="color: #000000; font-weight: bold;">//</span>hasseg.org</div></div>
</p>
<p>Here&#8217;s what it looks like on my desktop via GeekTool:<br />
<img src="http://hasseg.org/blog/wp-content/uploaded/2008/06/icalbuddy-geektook.png" alt="" title="icalbuddy-geektook" width="450" height="472" class="aligncenter size-full wp-image-145" /></p>
<p>
I have <a href="/icalBuddy/">a separate page</a> up on this site for the application itself, including download links, examples of use and documentation (read: HTML version of the man page,) so head on over there if you&#8217;re interested.</p>
]]></content:encoded>
			<wfw:commentRss>http://hasseg.org/blog/post/142/icalbuddy-getting-events-and-tasks-from-the-os-x-calendar-store-via-the-command-line/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
	</channel>
</rss>

