<?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>michael-mccracken.net &#187; mac</title>
	<atom:link href="http://michael-mccracken.net/tag/mac/feed/" rel="self" type="application/rss+xml" />
	<link>http://michael-mccracken.net</link>
	<description>This is a weblog</description>
	<lastBuildDate>Mon, 15 Mar 2010 02:23:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Snakes on Demand: How to write a Python Launchd Agent</title>
		<link>http://michael-mccracken.net/2010/03/snakes-on-demand-how-to-write-a-python-launchd-agent/</link>
		<comments>http://michael-mccracken.net/2010/03/snakes-on-demand-how-to-write-a-python-launchd-agent/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 02:23:52 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[launchd]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[macdev]]></category>
		<category><![CDATA[multiprocessing]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://michael-mccracken.net/?p=269</guid>
		<description><![CDATA[I share what I've learned about writing a Launchd agent that is mostly written in Python. This includes a link to a sample project hosted on bitbucket.]]></description>
			<content:encoded><![CDATA[<p>Suppose you want to write a Launchd agent in Python that communicates using UNIX domain sockets. There&#8217;s no sample code for that, but the information is out there to figure out how (especially because the <a href="http://launchd.macosforge.net">launchd source code</a> is available). Most search results will tell you that you need to read the <a href="http://developer.apple.com/mac/library/technotes/tn2005/tn2083.html">Daemons and Agents Tech Report TN2083</a>, but it&#8217;s pretty long and not a great tutorial. A better intro reference is Chris Hanson&#8217;s blog post <a href="http://chanson.livejournal.com/179229.html">&#8220;Launchd: better than sliced bread!&#8221;</a>, but that doesn&#8217;t tell you everything, and doesn&#8217;t mention Python.</p>

<p>I decided I&#8217;d share what I&#8217;ve learned recently to make getting started a little easier. I&#8217;ll give a short description here and post the resulting code to bitbucket at <a href="http://bitbucket.org/mikemccracken/py-launchd/">py-launchd</a>.</p>

<p><em>Note:</em> This was written and tested on OS X 10.5.8 with the default <code>/usr/bin/python</code>, version 2.5.1. 
Since I wanted to use multiprocessing, I used the backport to 2.5 available at <a href="http://code.google.com/p/python-multiprocessing/">google code: python-multiprocessing</a> . For convenience, it&#8217;s included in the repository, and so is its license.</p>

<h3>Goal</h3>

<p>What we&#8217;re trying to do is have some python code that gets called when launchd notices someone connecting to a <a href="http://en.wikipedia.org/wiki/Unix_domain_socket">UNIX domain socket</a>. UNIX domain sockets are local-only, so this is ideal for agents that only serve local apps. We&#8217;re also using launchd &#8220;agents&#8221; not &#8220;daemons&#8221;, so we&#8217;re assuming that it&#8217;s OK to have one agent process for each user. If you&#8217;re managing access to something that needs to be unique system-wide, then this won&#8217;t work (but you can still use Launchd).</p>

<h3>launchd overview</h3>

<p>The launchd process will read a launchd plist you give it (at login, via launchctl or the 10.6 framework), and listen on the socket you tell it to. Once it sees a connection, it&#8217;ll start the agent program you specified in the plist, and that program can make some calls using the launchd C API to get a file descriptor for the socket that was connected. This is important &#8211; you don&#8217;t need to call bind() or listen() on the socket, because launchd already did. It&#8217;s just handing the open socket&#8217;s file descriptor straight to you and your code can just call accept() on it.</p>

<h3>Using launchd with Python</h3>

<p>You need to create a C/ObjC tool that can do the launchd check-in to get the open file descriptor, then pass that off to your Python code. This is pretty straightforward using the Python framework included in OS X and the Python C APIs.</p>

<p>What I&#8217;ve done is create an agent loader that I called PyLaunchd that loads and runs server code in Agent.py. It expects Agent.py to be in the same directory.</p>

<p>PyLaunchd is built separately and copied into the test app&#8217;s Resources folder with an XCode script phase.</p>

<p>I have the app delegate copy <code>PyLaunchd</code> and <code>Agent.py</code> to <code>~/Library/Application Support/PyLaunchd/</code> on loading.
It also customizes the launchd plist to set the path correctly for the current user, then writes that to <code>~/Library/LaunchAgents/</code>, and loads it. (Actually it first unloads it, then reloads it. I&#8217;m not convinced this is the right way to do it). It uses system() to call launchctl, but I believe in OS X 10.6 there&#8217;s an API you can call to do it directly.</p>

<p>Finally, the sample app is really simple &#8211; it just opens the socket using the multiprocessing Client class, and sends whatever you type. The example Agent I&#8217;ve included will ROT13 it and send it back.</p>

<p>Please let me know if you have any comments, questions, or improvements.</p>]]></content:encoded>
			<wfw:commentRss>http://michael-mccracken.net/2010/03/snakes-on-demand-how-to-write-a-python-launchd-agent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>App History</title>
		<link>http://michael-mccracken.net/2009/11/app-history/</link>
		<comments>http://michael-mccracken.net/2009/11/app-history/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 18:02:06 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://michael-mccracken.net/?p=237</guid>
		<description><![CDATA[I just saw Brent&#8217;s post from a couple weeks ago about an App History App &#8211; I think that&#8217;d be really cool. I especially like the screen shot idea, since I love seeing posts from a developer showing what an app looked like along the progression. It&#8217;s too easy to forget to document that kind [...]]]></description>
			<content:encoded><![CDATA[<p>I just saw Brent&#8217;s post from a couple weeks ago about an <a href="http://inessential.com/2009/11/08/apphistory_app_idea">App History App</a> &#8211; I think that&#8217;d be really cool. I especially like the screen shot idea, since I love seeing posts from a developer showing what an app looked like along the progression. It&#8217;s too easy to forget to document that kind of thing, and I&#8217;d love it if we saw more of these behind-the-scenes posts.</p>]]></content:encoded>
			<wfw:commentRss>http://michael-mccracken.net/2009/11/app-history/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Measuring PDFs with Skim</title>
		<link>http://michael-mccracken.net/2009/11/measuring-pdfs-with-skim/</link>
		<comments>http://michael-mccracken.net/2009/11/measuring-pdfs-with-skim/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 22:00:07 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[skim]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://michael-mccracken.net/?p=231</guid>
		<description><![CDATA[

I love it when I can guess how to do something new in a program.
Skim just did this for me &#8211; I needed to figure out how big the rectangle of text in a paper I&#8217;m working on is, in inches. I looked for rulers, and then decided I&#8217;d just see if I get any [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://michael-mccracken.net/wp2/wp-content/uploads/2009/11/skimsnap.png" alt="Skim Measurement" title="Skim Measurement" width="210" height="128" class="alignright size-full wp-image-230" /></p>

<p>I love it when I can guess how to do something new in a program.
<a href="http://skim-app.sf.net">Skim</a> just did this for me &#8211; I needed to figure out how big the rectangle of text in a paper I&#8217;m working on is, in inches. I looked for rulers, and then decided I&#8217;d just see if I get any size feedback when I make a rectangular selection. Turns out there&#8217;s a nice feedback status line in the bottom right &#8211; clicking toggles between measurement in pts and in inches.</p>

<p>I like how this solves my problem without adding a lot of new UI for measurement &#8211; no rulers, no extra tool to measure length.</p>]]></content:encoded>
			<wfw:commentRss>http://michael-mccracken.net/2009/11/measuring-pdfs-with-skim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I&#8217;d like to see a community-run version&#8230;</title>
		<link>http://michael-mccracken.net/2009/10/id-like-to-see-a-community-run-version/</link>
		<comments>http://michael-mccracken.net/2009/10/id-like-to-see-a-community-run-version/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 17:08:41 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apps]]></category>
		<category><![CDATA[awards]]></category>
		<category><![CDATA[community]]></category>
		<category><![CDATA[mac]]></category>

		<guid isPermaLink="false">http://michael-mccracken.net/2009/10/id-like-to-see-a-community-run-version/</guid>
		<description><![CDATA[I&#8217;d like to see a community-run version of the Apple Design Awards.

Anyone could nominate an app, and the developer community would vote on who wins, in just a few categories.

I&#8217;m thinking the categories could be a little more user-centric than Apple&#8217;s. For instance, I don&#8217;t really care about best adoption of OS X technologies, but [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;d like to see a community-run version of the Apple Design Awards.</p>

<p>Anyone could nominate an app, and the developer community would vote on who wins, in just a few categories.</p>

<p>I&#8217;m thinking the categories could be a little more user-centric than Apple&#8217;s. For instance, I don&#8217;t really care about best adoption of OS X technologies, but something like &#8220;best refinement of a common task&#8221; or &#8220;best default behavior&#8221; or &#8220;best scriptability&#8221; would be interesting, and something that&#8217;d be easier to use as a marketing badge&#8230;</p>

<p>This is just off the top of my head, so there are probably others. &#8220;Least data lock-in&#8221;? &#8220;Easiest to learn?&#8221;, &#8220;Best plugin community&#8221;?</p>]]></content:encoded>
			<wfw:commentRss>http://michael-mccracken.net/2009/10/id-like-to-see-a-community-run-version/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>TextShapeView</title>
		<link>http://michael-mccracken.net/2009/09/textshapeview/</link>
		<comments>http://michael-mccracken.net/2009/09/textshapeview/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 17:49:37 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[NSTextView]]></category>
		<category><![CDATA[text]]></category>

		<guid isPermaLink="false">http://michael-mccracken.net/?p=192</guid>
		<description><![CDATA[TextShapeView was another Cocoa Text system hack project I started a few years ago.

I made a view that displays a zoomed out view of a string from a text view, with indentation, along with a rectangle showing where the text view is in the file.

You can click around in the view to move the  [...]]]></description>
			<content:encoded><![CDATA[<p>TextShapeView was another Cocoa Text system hack project I started a few years ago.</p>

<p>I made a view that displays a zoomed out view of a string from a text view, with indentation, along with a rectangle showing where the text view is in the file.</p>

<p>You can click around in the view to move the  It also highlights the selection, and draws lines in blue if they contain the string in the NSFindPBoard, so you can see <em>all</em> the lines in the file that match when you use the Find panel.</p>

<p>This is available under a Creative Commons license, and I&#8217;d ask that if you make any improvements, you send them back to me or join the &#8216;leverage&#8217; sourceforge project, where the code is hosted. I wanted to eventually make this into a Cocoa text plugin like <a href="http://michael-mccracken.net/2009/09/an-update-on-the-incremental-search-plug/">my I-Search plugin</a>.</p>

<p>Here is the <a href="http://leverage.svn.sourceforge.net/viewvc/leverage/textshape/trunk/">SVN repository for the textshape code</a>.</p>

<p>There was also a <a href="http://michael-mccracken.net/TextShapeView.tgz">Source code Tarball</a> with a demo app, shown in the screenshot below:</p>

<p><a href="http://michael-mccracken.net/img/tsvPic.png"  class="lightview"><img alt="" src="http://michael-mccracken.net/img/tsvPic.png" title="TextShapeView Sample image" width="50%" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://michael-mccracken.net/2009/09/textshapeview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prompted by a thread on the ever-useful &#8230;</title>
		<link>http://michael-mccracken.net/2009/08/prompted-by-a-thread-on-the-ever-useful/</link>
		<comments>http://michael-mccracken.net/2009/08/prompted-by-a-thread-on-the-ever-useful/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 21:15:29 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[location]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://michael-mccracken.net/wp/2009/08/20/prompted-by-a-thread-on-the-ever-useful/</guid>
		<description><![CDATA[Prompted by a thread on the ever-useful Sun internal mac-users alias, here&#8217;s a daemon that runs a script every time your network location changes:

Mac OS X LocationChanger &#8211; TECH.inhelsinki.nl.]]></description>
			<content:encoded><![CDATA[<p>Prompted by a thread on the ever-useful Sun internal mac-users alias, here&#8217;s a daemon that runs a script every time your network location changes:</p>

<p><a href="http://tech.inhelsinki.nl/locationchanger/">Mac OS X LocationChanger &#8211; TECH.inhelsinki.nl</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://michael-mccracken.net/2009/08/prompted-by-a-thread-on-the-ever-useful/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>From [@spamsieve](http://twitter.com/spa&#8230;</title>
		<link>http://michael-mccracken.net/2009/08/from-spamsievehttptwitter-comspa/</link>
		<comments>http://michael-mccracken.net/2009/08/from-spamsievehttptwitter-comspa/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 18:54:12 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[freeware]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[mailsmith]]></category>

		<guid isPermaLink="false">http://michael-mccracken.net/wp/2009/08/18/from-spamsievehttptwitter-comspa/</guid>
		<description><![CDATA[From @spamsieve, I heard that BareBones&#8217; Mailsmith has a new home:  mailsmith.org. It&#8217;s freeware and will be under development.

It&#8217;s great to see new life for one of the few alternative desktop mail clients for OS X, and while there&#8217;s no info on their plans for it yet, there&#8217;s some great discussion of possible features [...]]]></description>
			<content:encoded><![CDATA[<p>From <a href="http://twitter.com/spamsieve">@spamsieve</a>, I heard that BareBones&#8217; Mailsmith has a new home:  <a href="http://www.mailsmith.org">mailsmith.org</a>. It&#8217;s freeware and will be under development.</p>

<p>It&#8217;s great to see new life for one of the few alternative desktop mail clients for OS X, and while there&#8217;s no info on their plans for it yet, there&#8217;s some great discussion of possible features on the google group <a href="http://groups.google.com/group/mailsmith-talk">mailsmith-talk</a>.</p>

<p>I&#8217;ll be curious to see if any of the design choices will be changing &#8211; for example, no IMAP support and no inline HTML display&#8230; I have to use IMAP, and despite common abuse, I do think HTML email is useful.</p>

<p><strong>edit</strong>: Looks like no Mailsmith IMAP: &#8220;Not any time soon…&#8221; – <a href="http://twitter.com/siegel/status/3386768085">@siegel on twitter</a></p>]]></content:encoded>
			<wfw:commentRss>http://michael-mccracken.net/2009/08/from-spamsievehttptwitter-comspa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title></title>
		<link>http://michael-mccracken.net/2009/08/from-the-hn-threadhttpnews-ycombin/</link>
		<comments>http://michael-mccracken.net/2009/08/from-the-hn-threadhttpnews-ycombin/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 06:37:27 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[mail]]></category>

		<guid isPermaLink="false">http://michael-mccracken.net/wp/2009/08/06/from-the-hn-threadhttpnews-ycombin/</guid>
		<description><![CDATA[From the HN thread on this post from Garry at posterous, about product minimalism:

Teams at apple are TINY. Mail is like 3 guys. …

Two things: The thread was about how high quality software is easier without politics you get in large teams, which I agree with, and I bet that a lot of the software [...]]]></description>
			<content:encoded><![CDATA[<p>From the <a href="http://news.ycombinator.com/item?id=747096">HN thread</a> on <a href="http://garry.posterous.com/practicing-product-minimalism">this post</a> from Garry at posterous, about product minimalism:</p>

<blockquote>Teams at apple are TINY. Mail is like 3 guys. …</blockquote>

<p>Two things: The thread was about how high quality software is easier without politics you get in large teams, which I agree with, and I bet that a lot of the software we love was made by smaller teams than you&#8217;d think.</p>

<p>And, just 3 engineers on Mail explains a lot.</p>]]></content:encoded>
			<wfw:commentRss>http://michael-mccracken.net/2009/08/from-the-hn-threadhttpnews-ycombin/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New Release of EagleFiler</title>
		<link>http://michael-mccracken.net/2009/07/new-release-of-eaglefiler/</link>
		<comments>http://michael-mccracken.net/2009/07/new-release-of-eaglefiler/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 18:22:11 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[organization]]></category>
		<category><![CDATA[productivity]]></category>

		<guid isPermaLink="false">http://michael-mccracken.net/wp/?p=156</guid>
		<description><![CDATA[From C-Command Blog &#8211;  EagleFiler 1.4.7: a bunch of nice refinements.

I use EagleFiler to keep track of reference documents that I get in emails. Presentations, reports, etc &#8211; the kind of thing that would usually just get stored in the mail archive. Because I want a complete mail archive and a fast way to [...]]]></description>
			<content:encoded><![CDATA[<p>From <a href="http://c-command.com/blog/2009/07/28/eaglefiler-147/">C-Command Blog &#8211;  EagleFiler 1.4.7</a>: a bunch of nice refinements.</p>

<p>I use EagleFiler to keep track of reference documents that I get in emails. Presentations, reports, etc &#8211; the kind of thing that would usually just get stored in the mail archive. Because I want a complete mail archive <em>and</em> a fast way to get to the important stuff, I keep the important stuff in EagleFiler so I can add tags and searches don&#8217;t get a lot of false hits.</p>]]></content:encoded>
			<wfw:commentRss>http://michael-mccracken.net/2009/07/new-release-of-eaglefiler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Subversion Client Issues</title>
		<link>http://michael-mccracken.net/2009/07/subversion-clients/</link>
		<comments>http://michael-mccracken.net/2009/07/subversion-clients/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 14:17:14 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[gui]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://michael-mccracken.net/wp/?p=134</guid>
		<description><![CDATA[I do a quick one-bullet review of Mac SVN clients.]]></description>
			<content:encoded><![CDATA[<p>I use subversion, and won&#8217;t switch to something newer for a while, so it&#8217;s worth looking at how to polish that old hammer. I&#8217;m used to using the command line svn, or emacs. But recently I decided to try out a few of the nice GUI clients that are around, including <a href="http://versionsapp.com/">Versions</a>, <a href="http://zigzig.com/">ZigVersion</a> and <a href="http://www.zennaware.com/cornerstone/">Cornerstone</a>.</p>

<p>Of these, the only one that&#8217;s polished enough to lure me away from emacs and seems to support my favorite mode of working is Cornerstone, and it still gets it a little wrong.</p>

<p>I like to write log comments while looking at (and scrolling through) the diffs for the files I&#8217;m committing. This means I want a text field for writing log comments on the same screen as the diffs, that isn&#8217;t modal, and doesn&#8217;t stop me from moving around between multiple diffs.</p>

<p>As far as I could tell, I couldn&#8217;t get the comment field and the diff display shown together in Versions, and while I could in ZigVersion, that app had a subpar diff display and lacked polish overall, missing key shortcuts where I&#8217;d expect them, for instance. Cornerstone almost lets me do what I want, but it displays the comment field in a modal sheet, so I have to cancel to change which diff I&#8217;m looking at.</p>

<p>This is easy in emacs, but I like a nicer diff GUI. Am I just missing something? This feels like a natural workflow, so it seems strange that no clients support it well.</p>]]></content:encoded>
			<wfw:commentRss>http://michael-mccracken.net/2009/07/subversion-clients/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
