<?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</title>
	<atom:link href="http://hasseg.org/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://hasseg.org/blog</link>
	<description></description>
	<lastBuildDate>Fri, 20 Aug 2010 09:52:19 +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>Use Unicode Emoji as Image-Free Icons in iOS Web Apps</title>
		<link>http://hasseg.org/blog/post/546/use-unicode-emoji-as-image-free-icons-in-ios-web-apps/</link>
		<comments>http://hasseg.org/blog/post/546/use-unicode-emoji-as-image-free-icons-in-ios-web-apps/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 22:59:37 +0000</pubDate>
		<dc:creator>Ali Rantakari</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[iOS]]></category>

		<guid isPermaLink="false">http://hasseg.org/blog/?p=546</guid>
		<description><![CDATA[In version 2.2 of iOS &#8212; Apple&#8217;s &#8220;mobile&#8221; operating system used in the iPhone, iPod Touch and iPad &#8212; support for Emoji was added. These small 12&#215;12 pixel icons are meant to be used in text messaging in Japan but because they&#8217;re implemented simply as unicode symbols in the device they can be used as [...]]]></description>
			<content:encoded><![CDATA[<p>
<img src="http://hasseg.org/blog/wp-content/uploaded/2010/07/emoji-small.png" alt="" title="" width="57" height="57" align="right" /> In version 2.2 of <a href="http://en.wikipedia.org/wiki/IOS_(Apple)">iOS</a> &mdash; Apple&#8217;s &#8220;mobile&#8221; operating system used in the <em>iPhone</em>, <em>iPod Touch</em> and <em>iPad</em> &mdash; support for <a href="http://en.wikipedia.org/wiki/Emoji">Emoji</a> was added. These small 12&#215;12 pixel icons are meant to be used in text messaging in Japan but because they&#8217;re implemented simply as unicode symbols in the device <strong>they can be used as icons</strong> when we know they&#8217;re available.
</p>
<p><span id="more-546"></span></p>
<h2>Emoji and Unicode</h2>
<p>
Emoji is basically a Japanese term for emoticons used on mobile devices. <a href="http://en.wikipedia.org/wiki/Emoji">The Wikipedia article</a> has more information on the concept, but this part is the most interesting:
</p>
<blockquote><p>
When transmitted, emoji symbols are specified as a two-byte sequence, in the private-use range E63E through E757 in the Unicode character space, or F89F through F9FC for Shift-JIS.
</p></blockquote>
<p>
Now, that&#8217;s <em>not true</em> for Apple&#8217;s Emoji implementation &mdash; it&#8217;s apparently completely incompatible with the handsets from the Japanese carriers (see <a href="http://openradar.appspot.com/6402446">OpenRadar #6402446</a> for more info) &mdash; but the part about them being implemented as unicode symbols <em>is</em> still true in iOS, the code points used are just different.
</p>
<p>
I&#8217;ve made <a href="/stuff/ios-emoji/">this demo page</a> that <strong>lists unicode symbols and the hexadecimal code points for all the different Emoji that are available on my iPhone</strong> (iOS version 4). The demo page has a cache manifest so it should be available offline as well. If you&#8217;re currently on a desktop computer you won&#8217;t be able to see them so here&#8217;s a picture of what it looks like on the iPhone:
</p>
<div style="text-align:center;">
<img src="http://hasseg.org/blog/wp-content/uploaded/2010/07/emoji-page.png" alt="" title="" width="229" height="335" />
</div>
<p>
In order to be able to use these icons you need to have easy access to the hexadecimal unicode code points so this page should come in handy. If you instead prefer a native app for this, there are <a href="http://www.google.com/search?q=site%3Aitunes.apple.com+inurl%3A%22%2Fapp%2F%22+unicode">many you can choose from</a>.
</p>
<h2>Using Emoji Symbols in HTML and CSS</h2>
<p>
User agent detection is usually cited as a bad thing, and with good reason &mdash; it&#8217;s often used when <a href="http://diveintohtml5.org/detect.html">feature detection</a> would be more appropriate, causing unexpected breakage in many edge conditions. When planning on using the iOS emoji on a web page, though, <strong>you really need to sniff the user agent</strong> in order to know whether the client is an iOS device and thus has a font that implements these unicode symbols in the expected way.
</p>
<p>
Here&#8217;s an example (in PHP) of how you&#8217;d detect iOS devices:
</p>
<div class="codecolorer-container php mac-classic codecolorer-customstyle" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$is_iPhone</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'iPhone'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$is_iPod</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'iPod'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$is_iPad</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'iPad'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$is_iOS</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$is_iPad</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$is_iPod</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$is_iPhone</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>
When you&#8217;ve detected the client to be an iOS device, you can <strong>offer them an additional stylesheet:</strong>
</p>
<div class="codecolorer-container php mac-classic codecolorer-customstyle" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$is_iOS</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;iOS.css&quot; /&gt;'</span><span style="color: #339933;">;</span></div></div>
<p>
In this stylesheet you&#8217;ll then insert the Emoji symbols into whatever locations you&#8217;d like to use them in, and to do this you can use <a href="http://www.w3.org/TR/CSS2/generate.html">CSS2&#8242;s content generation mechanisms</a> (in the examples below, we use code point E00E, which is the &#8220;thumbs up&#8221; Emoji):
</p>
<div class="codecolorer-container css mac-classic codecolorer-customstyle" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #cc00cc;">#someID</span><span style="color: #3333ff;">:before </span><span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">content</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\E</span>00E&quot;</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* thumbs up */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span></div></div>
<p>
Containing all the iOS-specific embellishments in one separate CSS file is, I think, the way to go, but if you want you can also insert these symbols directly into your HTML as special entities:
</p>
<div class="codecolorer-container html4strict mac-classic codecolorer-customstyle" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span><span style="color: #ddbb00;">&amp;#xE00E;</span> Thumbs up!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></div></div>
<h2>Big Caveats to Consider</h2>
<p>
This is a great way to add little graphical cues to your web app <strong>without having to deal with images</strong> (i.e. making or obtaining them, serving them, having the app load them, possibly caching them) but of course the downside is that they are <strong>only available on Apple&#8217;s iOS devices</strong>, which makes this trick quite useless unless you&#8217;re concentrating completely on the iPhone/iPad/iPod Touch axis.
</p>
<p>
The key takeaway from this should be that there&#8217;s this <strong>neat trick</strong> you can use but <strong>if you <em>need</em> your icons to be visible in all clients</strong> you should forget about these and <strong>just use images for everyone</strong> (it&#8217;ll be much easier).
</p>
<div class="note" style="margin-bottom:50px;"><strong>Note:</strong> I&#8217;ve noticed that for some reason these emoji characters will <strong>fail to render on the iPad if the <span style="font-family:monospace;">text-rendering</span> CSS property is set to <span style="font-family:monospace;">optimizeLegibility</span></strong> <em>(this is on the iPad-specific build of iOS 3.2, MobileSafari Version/4.0.4 Mobile/7B367 Safari/531.21.10 and does not occur on my iPhone (which is running iOS 4.0.1))</em>.</div>
]]></content:encoded>
			<wfw:commentRss>http://hasseg.org/blog/post/546/use-unicode-emoji-as-image-free-icons-in-ios-web-apps/feed/</wfw:commentRss>
		<slash:comments>2</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 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>2</slash:comments>
		</item>
		<item>
		<title>Getting a List of Installed Fonts with Flash and Javascript</title>
		<link>http://hasseg.org/blog/post/526/getting-a-list-of-installed-fonts-with-flash-and-javascript/</link>
		<comments>http://hasseg.org/blog/post/526/getting-a-list-of-installed-fonts-with-flash-and-javascript/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 23:18:05 +0000</pubDate>
		<dc:creator>Ali Rantakari</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Miscallaneous]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://hasseg.org/blog/?p=526</guid>
		<description><![CDATA[When implementing the feature in the icalBuddy examples page where the font used for the output examples could be changed interactively I needed to get a list of all the fonts installed on the current user&#8217;s computer. This blog post from 2006 explains how to do it, but it refers to the deprecated ActionScript 2 [...]]]></description>
			<content:encoded><![CDATA[<p>
<img src="http://hasseg.org/blog/wp-content/uploaded/2010/07/flash-fonts.png" alt="" title="" width="90" height="104" align="right" /> When implementing the feature in the <a href="/icalBuddy/examples.html">icalBuddy examples page</a> where the font used for the output examples could be changed interactively I needed to <strong>get a list of all the fonts installed on the current user&#8217;s computer</strong>. <a href="http://www.maratz.com/blog/archives/2006/08/18/detect-visitors-fonts-with-flash/">This blog post from 2006</a> explains how to do it, but it refers to the deprecated ActionScript 2 API so I had to figure out how to do it with AS3.
</p>
<p><span id="more-526"></span></p>
<h3>Demo</h3>
<p>
Here&#8217;s a small demo where you can see the feature at work: <a href="/stuff/fontList/example.html">Font List Example</a>. The sources shown below are used in this demo.
</p>
<h3>Implementation</h3>
<p>
We need <strong>a small Flash app and some Javascript</strong>. Below is the source code for the Flash app.
</p>
<p>
<em>Note that you don&#8217;t need the Flash authoring app from Adobe in order to compile this; you can simply use the <span style="font-family:monospace;">mxmlc</span> compiler in the <a href="http://opensource.adobe.com/wiki/display/flexsdk/">Flex SDK</a> (which is open source).</em>
</p>
<div class="codecolorer-container actionscript mac-classic codecolorer-customstyle" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// FontList.as</span><br />
package <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">Font</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #006600;">FontType</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #006600;">FontStyle</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">external</span>.<span style="color: #006600;">ExternalInterface</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> FontList <span style="color: #0066CC;">extends</span> Sprite<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> FontList<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ExternalInterface.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'populateFontList'</span>, getDeviceFonts<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getDeviceFonts<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Array</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> embeddedAndDeviceFonts:<span style="color: #0066CC;">Array</span> = <span style="color: #0066CC;">Font</span>.<span style="color: #006600;">enumerateFonts</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> deviceFontNames:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #b1b100;">each</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">font</span>:<span style="color: #0066CC;">Font</span> <span style="color: #b1b100;">in</span> embeddedAndDeviceFonts<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">font</span>.<span style="color: #006600;">fontType</span> == FontType.<span style="color: #006600;">EMBEDDED</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">||</span> <span style="color: #0066CC;">font</span>.<span style="color: #006600;">fontStyle</span> <span style="color: #66cc66;">!</span>= FontStyle.<span style="color: #006600;">REGULAR</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">continue</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; deviceFontNames.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">font</span>.<span style="color: #006600;">fontName</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; deviceFontNames.<span style="color: #0066CC;">sort</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> deviceFontNames;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>
Notice how the Flash app calls a Javascript function <span style="font-family:monospace;">populateFontList()</span> via the ExternalInterface. Now we just need to implement that function in the page where we embed the Flash object:
</p>
<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"><span style="color: #003366; font-weight: bold;">function</span> populateFontList<span style="color: #009900;">&#40;</span>fontArr<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> key <span style="color: #000066; font-weight: bold;">in</span> fontArr<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> fontName <span style="color: #339933;">=</span> fontArr<span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// trim</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; fontName <span style="color: #339933;">=</span> fontName.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^\s\s*/</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\s\s*$/</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fontName.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/[_\-\s]Italic$/</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">||</span> fontName.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/[_\-\s](Demi)?[Bb]old$/</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">||</span> fontName.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/[_\-\s]Medium$/</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">||</span> fontName.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/[_\-\s](Ultra)?[Ll]ight$/</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">||</span> fontName.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/[_\-\s]Condensed$/</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// font is &quot;non-regular&quot; (i.e. bold, italic etc.)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// (do something here with fontName)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// font is &quot;regular&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// (do something here with fontName)</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://hasseg.org/blog/post/526/getting-a-list-of-installed-fonts-with-flash-and-javascript/feed/</wfw:commentRss>
		<slash:comments>3</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>2</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>3</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>10</slash:comments>
		</item>
		<item>
		<title>Quick, Declarative UML Sequence Diagrams</title>
		<link>http://hasseg.org/blog/post/329/quick-declarative-uml-sequence-diagrams/</link>
		<comments>http://hasseg.org/blog/post/329/quick-declarative-uml-sequence-diagrams/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 13:34:55 +0000</pubDate>
		<dc:creator>Ali Rantakari</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[jEdit]]></category>

		<guid isPermaLink="false">http://hasseg.org/blog/?p=329</guid>
		<description><![CDATA[I recently had to create a few UML sequence diagrams, and I decided that I didn&#8217;t want to spend too much time manually tweaking and fixing the diagrams themselves (which is what I probably would&#8217;ve done, had I used OmniGraffle or something similar), but instead focus on the content &#8212; the depicted workflow itself. This [...]]]></description>
			<content:encoded><![CDATA[<p>
<img align="right" src="http://hasseg.org/blog/wp-content/uploaded/2009/06/wsd-example-diagram-small.png" alt="wsd-example-diagram-small" width="113" height="86" /> I recently had to create a few UML sequence diagrams, and I decided that I didn&#8217;t want to spend too much time manually tweaking and fixing the diagrams themselves (which is what I probably would&#8217;ve done, had I used <em>OmniGraffle</em> or something similar), but instead <strong>focus on the <em>content</em></strong> &mdash; the depicted workflow itself. This is when I remembered the bookmark I had in my browser for the <strong><a href="http://www.websequencediagrams.com">Web Sequence Diagrams</a> online service</strong>.
</p>
<p><span id="more-329"></span></p>
<h2>Benefits of Declarative Diagramming</h2>
<p><em>Web Sequence Diagrams</em> is great. It uses <strong><a href="http://www.websequencediagrams.com/examples.html">a simple, readable syntax</a></strong> you can use to type in descriptions of sequential workflows and based on that it will <strong>generate the corresponding UML sequence diagrams</strong> for you.</p>
<p>
Working with these diagrams in this way has a couple of <strong>nice benefits</strong> over more intricate/professional methods:
</p>
<ul>
<li>They&#8217;re quick to create and quick to modify</li>
<li>The syntax is pretty easy to read as-is</li>
<li>The source is plain text, so all the benefits of using plain text apply (e.g. <em>can put under source control</em>, <em>can use simple diff tools</em>, <em>file sizes are small</em> etc.)</li>
</ul>
<h2>Helper Script and Syntax Highlighting</h2>
<p>
When I was sure I wanted to use this method again in the future, I hacked up a few quick and simple tools for this:
</p>
<h3>Script for generating the diagram images from source files</h3>
<p>At the time of this writing, there&#8217;s <a href="http://websequencediagrams.uservoice.com/pages/9445-general/suggestions/101931-create-a-command-line-version-of-this-application-">a suggestion called &#8220;Create a command-line version of this application&#8221;</a> on the service&#8217;s <em>UserVoice</em> site that&#8217;s labeled <em>&#8220;started&#8221;</em>, so hopefully in the future we&#8217;ll have a command-line sequence diagram generator from the author of the online service. In the meantime, though, here&#8217;s my solution. This is <strong>a Python script</strong> that can be used for generating the diagram images (using this service) from &#8220;source files&#8221; that contain the declarative workflow syntax. You just need to:</p>
<ol>
<li>type up your diagram description in a text editor and save it into a file</li>
<li>begin the first line in the file with <span style="font-family:monospace;">#wsd</span> (so that the script knows this is a websequencediagrams.com syntax file)</li>
<li><em>(optional:)</em> specify the <a href="http://www.websequencediagrams.com/embedding.html">diagram style</a> you&#8217;d like to use on the first line with the syntax <span style="font-family:monospace;">#wsd:style=modern-blue</span></li>
<li>call the script with the path to this file as an argument to generate the diagram image</li>
</ol>
<p>
The script uses a temporary <a href="http://www.sqlite.org/">SQLite</a> database to <strong>save hashes of file contents</strong> so that even if you call it repeatedly for the same file, it&#8217;ll notice if the file contents haven&#8217;t changed and decide not to send a request over to the server. I did this in order to reduce unnecessary load on the server. I tested the script on <strong>Mac OS 10.5.7, Windows XP SP3 and Ubuntu 9.04</strong> and it seems to work just fine on all of those (of course, on Windows you&#8217;ll first have to install <a href="http://www.python.org/download/">Python</a> manually).
</p>
<p><strong>Download</strong> the script here: <a href="/stuff/wsd/wsd.py">wsd.py</a></p>
<p>
Here&#8217;s an example on how to use it (to see the script&#8217;s <em>usage</em> info, run it without any arguments):
</p>
<p>Save this into a file called <em>ax-diagram</em>:</p>
<pre class="prettyprint">
#wsd

participant "Component A" as A
participant "Component X" as X

X -> A: what up
A -> A: processWhatUp()
note over A: A is confused
A -> X: go away
destroy X
</pre>
<p>Then run the script:</p>
<pre class="prettyprint">
wsd.py ax-diagram
</pre>
<p>
&#8230;and the file <em>ax-diagram.png</em> is created:
</p>
<p><img src="http://hasseg.org/blog/wp-content/uploaded/2009/06/wsd-example-diagram.png" alt="example diagram" width="323" height="247" /></p>
<h3>jEdit syntax highlighting mode</h3>
<p>This is a simple jEdit syntax highlighting mode for the Web Sequence Diagrams syntax. You can <strong>download</strong> the file here: <a href="/stuff/wsd/websequencediagrams.xml">websequencediagrams.xml</a>. Refer to <a href="?p=302">this other blog post of mine</a> for instructions on how to install modes for jEdit.</p>
<p>
Here&#8217;s a screenshot of the highlighted syntax on my machine:
</p>
<p><img src="http://hasseg.org/blog/wp-content/uploaded/2009/06/wsd-syntax.png" alt="websequencediagram.com syntax highlighting screenshot" width="249" height="166" /></p>
]]></content:encoded>
			<wfw:commentRss>http://hasseg.org/blog/post/329/quick-declarative-uml-sequence-diagrams/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Markdown and POD Syntax Highlighting Modes for jEdit</title>
		<link>http://hasseg.org/blog/post/302/markdown-and-pod-syntax-highlighting-modes-for-jedit/</link>
		<comments>http://hasseg.org/blog/post/302/markdown-and-pod-syntax-highlighting-modes-for-jedit/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 13:44:45 +0000</pubDate>
		<dc:creator>Ali Rantakari</dc:creator>
				<category><![CDATA[jEdit]]></category>

		<guid isPermaLink="false">http://hasseg.org/blog/?p=302</guid>
		<description><![CDATA[In The Pragmatic Programmer&#185;, the authors Andrew Hunt and David Thomas empasize the power of plain text, as well as &#8220;generators&#8221; that take the canonical form of some document and generate different representations of it. This is very much in line with the way I like to work with a lot of documents, which is [...]]]></description>
			<content:encoded><![CDATA[<p>
In <em>The Pragmatic Programmer</em><a href="#fn1">&sup1;</a>, the authors Andrew Hunt and David Thomas empasize the power of plain text, as well as &#8220;generators&#8221; that take the canonical form of some document and generate different representations of it. This is very much in line with the way I like to work with a lot of documents, which is why I&#8217;ve been using the <strong>Markdown</strong> and <strong>POD (Plain Old Documentation)</strong> syntaxes for a couple of things. As jEdit is the editor I prefer to use for working with most plain-text formats, I wrote highlighting modes for it for these two syntaxes.
</p>
<div style="padding:4px;background:#eee;border:1px solid #ddd;">
<em><strong>Update (April 23, 09):</strong> Updated the Markdown mode with slightly better handling of code blocks and list item paragraphs as well as some comments about problems therein (see below in the post for more info on this).</em>
</div>
<p><span id="more-302"></span></p>
<h2>The Markdown jEdit mode</h2>
<p><img src="http://hasseg.org/blog/wp-content/uploaded/2009/04/markdown-highlighting.png" alt="Markdown jEdit mode screenshot" title="markdown-highlighting" width="419" height="256" class="size-full wp-image-310" /></p>
<p>
<a href="http://daringfireball.net/projects/markdown/">Markdown</a> is my favourite markup language. Its primary design principle, that the markup written in it should be <strong>as readable as possible</strong> even by itself, is something my plain text -loving mind can easily agree with. If I&#8217;m writing a document that needs to be represented as HTML later on, Markdown is my first choice (too bad <a href="http://michelf.com/weblog/2005/wordpress-text-flow-vs-markdown/">it doesn&#8217;t work very well with WordPress</a>).
</p>
<p>
<strong>Here&#8217;s my jEdit mode file for Markdown:</strong> <a href="/stuff/jedit-modes/markdown.xml">markdown.xml</a>.
</p>
<p>
To install this mode, add the following to the <span style="font-family:monospace;">modes/catalog</span> file in your jEdit user settings directory (select <em>Utilities &rarr; Settings Directory</em> in jEdit to find this):
</p>
<pre class="prettyprint">
<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">&lt;MODE &nbsp; NAME=&quot;markdown&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; FILE=&quot;markdown.xml&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; FILE_NAME_GLOB=&quot;*.markdown&quot;<br />
/&gt;</div></div>
</pre>
<p>
Then copy the <span style="font-family:monospace;">markdown.xml</span> file into the same directory with this file. See <a href="http://www.jedit.org/users-guide/installing-modes.html">the Installing Modes section</a> of the jEdit users&#8217; guide for more information.
</p>
<p>
This mode is not perfect; I could not figure out how to properly differentiate between <em>code blocks</em> and <em>list item paragraphs</em> (both are indented by 4+ spaces or 1+ tabs). Here&#8217;s what I wrote into the mode file related to these:
</p>
<pre class="prettyprint">
<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">&lt;!-- PROBLEM: code blocks<br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp;Both code blocks and list paragraphs are specified by indenting<br />
&nbsp; &nbsp; &nbsp;(4+ spaces or 1+ tab) - how to differentiate between them? We<br />
&nbsp; &nbsp; &nbsp;don't want markdown syntax coloring to apply within code blocks<br />
&nbsp; &nbsp; &nbsp;but we _do_ want it to apply within list paragraphs. As it stands,<br />
&nbsp; &nbsp; &nbsp;we can't have both (or at least I don't know how to do that with<br />
&nbsp; &nbsp; &nbsp;jEdit's current mode syntax implementation.)<br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp;The next line applies one syntax color type for all lines that<br />
&nbsp; &nbsp; &nbsp;begin with at least 4 spaces or 1 tab, which means that all such<br />
&nbsp; &nbsp; &nbsp;lines are treated as code blocks (this disables markdown syntax<br />
&nbsp; &nbsp; &nbsp;coloring for indented list paragraphs). Comment or uncomment it<br />
&nbsp; &nbsp; &nbsp;according to your preferences.<br />
--&gt;<br />
&lt;EOL_SPAN_REGEXP TYPE=&quot;LITERAL2&quot; AT_LINE_START=&quot;TRUE&quot; HASH_CHARS=&quot; &amp;#09;&quot;&gt;(\s{4,}|\t+)&lt;/EOL_SPAN_REGEXP&gt;<br />
&lt;!-- The next line applies one syntax color type for all lines that<br />
&nbsp; &nbsp; &nbsp;are indented &quot;twice&quot; (i.e. begin with at least 8 spaces or 2 tabs).<br />
&nbsp; &nbsp; &nbsp;This should safely match only code blocks (no list paragraphs can<br />
&nbsp; &nbsp; &nbsp;be indented twice like this, if I understand the spec correctly.)<br />
--&gt;<br />
&lt;EOL_SPAN_REGEXP TYPE=&quot;LITERAL2&quot; AT_LINE_START=&quot;TRUE&quot; HASH_CHARS=&quot; &amp;#09;&quot;&gt;(\s{4,}|\t+){2,}&lt;/EOL_SPAN_REGEXP&gt;</div></div>
</pre>
<p>Here&#8217;s how you&#8217;d generate a HTML file from a Markdown file:</p>
<pre class="prettyprint">
<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">perl Markdown.pl myDocument.markdown &gt; myDocument.html</div></div>
</pre>
<h2>The POD jEdit mode</h2>
<p><img src="http://hasseg.org/blog/wp-content/uploaded/2009/04/pod-highlighting.png" alt="POD jEdit mode screenshot" title="pod-highlighting" width="377" height="220" class="size-full wp-image-311" /></p>
<p>
When writing documentation for <a href="/icalBuddy">icalBuddy</a>, I had to enter the wonderful world of creating <a href="http://en.wikipedia.org/wiki/Manual_page_(Unix)">man pages</a> for the first time. The raw syntax for writing these things is, to say the least, awful. Just awful. Unfortunately I can&#8217;t use Markdown for writing them, but a pretty nice alternative I found was <a href="http://en.wikipedia.org/wiki/Plain_Old_Documentation">POD</a> (or <em>&#8220;Plain Old Documentation&#8221;</em>), which is mainly used to document Perl code. Now, the important thing to note about this mode is that I don&#8217;t know any Perl, I don&#8217;t code in Perl and I have no idea how POD is used with Perl, so <strong>this mode is not suitable for simultaneous use of Perl and POD</strong> &mdash; I just wrote it for syntax highlighting in the pure POD documents I use to write man pages. Adjusting it to work for the purposes of documenting Perl code might just be trivial for someone who does know Perl and how POD is used with it, but I can&#8217;t do it.
</p>
<p>
<strong>Here&#8217;s my jEdit mode file for POD:</strong> <a href="/stuff/jedit-modes/pod.xml">pod.xml</a>. Refer to the installation instructions for the Markdown mode above to see how this should be taken into use &mdash; the process is similar.
</p>
<p>Here&#8217;s how you&#8217;d generate a man page from a POD file:</p>
<pre class="prettyprint">
pod2man --section=1 --release=1.0 --center="manpage_title" --date="2009-04-21" myManPage.pod > myManPage.1
</pre>
<h3 style="margin-top:50px;">Footnotes</h3>
<ol>
<li id="fn1"><a href="http://www.amazon.com/Pragmatic-Programmer-Journeyman-Master/dp/020161622X">The Pragmatic Programmer</a> (ISBN 0-201-61622-X): Chapter 3 (<em>&#8220;The Basic Tools&#8221;</em>), Sections <em>&#8220;The Power of Plain Text&#8221;</em> (pages 73-77) and <em>&#8220;Code Generators&#8221;</em> (pages 102-106). </li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://hasseg.org/blog/post/302/markdown-and-pod-syntax-highlighting-modes-for-jedit/feed/</wfw:commentRss>
		<slash:comments>0</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>
	</channel>
</rss>
