<?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>Red Sweater Blog &#187; Hacking</title>
	<atom:link href="http://www.red-sweater.com/blog/category/articles/hacking/feed" rel="self" type="application/rss+xml" />
	<link>http://www.red-sweater.com/blog</link>
	<description>Mac &#38; Technology Writings by Daniel Jalkut</description>
	<lastBuildDate>Tue, 17 Jan 2012 22:03:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>QuickLogin Plugin For WordPress</title>
		<link>http://www.red-sweater.com/blog/2119/quicklogin-plugin-for-wordpress</link>
		<comments>http://www.red-sweater.com/blog/2119/quicklogin-plugin-for-wordpress#comments</comments>
		<pubDate>Sun, 07 Aug 2011 18:49:37 +0000</pubDate>
		<dc:creator>Daniel Jalkut</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.red-sweater.com/blog/?p=2119</guid>
		<description><![CDATA[This blog runs on WordPress, which has been a great solution for my needs. But as the developer of MarsEdit, you might guess I get the opportunity to see a whole heckuva lot of other systems, and sometimes find myself envious of their advantages, big and small. One such advantage I noticed is that Squarespace [...]]]></description>
			<content:encoded><![CDATA[<p>This blog runs on <a href="http://wordpress.org/">WordPress</a>, which has been a great solution for my needs. But as the developer of <a href="http://www.red-sweater.com/marsedit/">MarsEdit</a>, you might guess I get the opportunity to see <em>a whole heckuva lot</em> of other systems, and sometimes find myself envious of their advantages, big and small.</p>
<p>One such advantage I noticed is that <a href="http://www.squarespace.com/">Squarespace</a> users can log in from any page on their blog, just by <a href="http://help.squarespace.com/customer/portal/articles/10974-i-hid-my-login-prompt-on-my-website-how-do-i-log-in-now-">pressing the escape key</a>.</p>
<p>By default, WordPress requires that you either memorize the admin page URL, or list an ugly &#8220;Login&#8221; link i the blog&#8217;s template. I never liked the idea of having a login link for a site that <em>only I should ever be logging in to</em>, so for years I have omitted the login link from my site.</p>
<p>This means that when I&#8217;m reading comments or something on my site, and am not logged in, I have to do a silly dance before I respond or moderate a comment:</p>
<ol>
<li>Go to the URL bar in my browser.</li>
<li>Change URL to /wp-admin/</li>
<li>Enter the proper login credentials.</li>
<li>Hit back button to get back where I was.</li>
<li>Reload the page to see the comment form as a logged-in user.</li>
</ol>
<p>This ends today. My <a href="https://github.com/danielpunkass/QuickLogin">QuickLogin Plugin</a> for WordPress is a drop-in solution that, when activated, gives your WordPress blog the same delicious escape-key behavior that Squarespace offers. Now when I am browsing my own blog and want to log in, I just press the escape key. After I authenticate, I&#8217;m automatically returned to the reloaded page I was viewing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.red-sweater.com/blog/2119/quicklogin-plugin-for-wordpress/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>The Power Of Plist</title>
		<link>http://www.red-sweater.com/blog/2083/the-power-of-plist</link>
		<comments>http://www.red-sweater.com/blog/2083/the-power-of-plist#comments</comments>
		<pubDate>Wed, 03 Aug 2011 19:12:50 +0000</pubDate>
		<dc:creator>Daniel Jalkut</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Darwin]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://www.red-sweater.com/blog/?p=2083</guid>
		<description><![CDATA[Most Mac and iOS developers know that when you build an application, you advertise a number of details about the application in the &#8220;Info.plist&#8221; file, located inside the application bundle. You can examine any application on your Mac and see what kind of information the developer has conveyed about it: Navigate to a .app file [...]]]></description>
			<content:encoded><![CDATA[<p>Most Mac and iOS developers know that when you build an application, you advertise a number of details about the application in the &#8220;Info.plist&#8221; file, located inside the application bundle. You can examine any application on your Mac and see what kind of information the developer has conveyed about it:</p>
<ol>
<li>Navigate to a .app file in the Finder, e.g. /Applications/Mail.app</li>
<li>Control-click the app icon and select &#8220;Show Package Contents&#8221;</li>
<li>Navigate to Contents/Info.plist</li>
<li>Open with a plist editor or your favorite text editor.</li>
</ol>
<p>These files advertise a number of interesting attributes including the application&#8217;s official version and copyright strings. They also include important clues to the system about what kinds of files the application knows how to read and write, and what its minimum system requirements are.</p>
<h3>Minimum System Requirements</h3>
<p>Declaring the right Info.plist values not only allows a developer to control which operating systems a product should run on, but which of the application&#8217;s architectures should be considered for a particular operating system. For example, <a href="http://www.red-sweater.com/blackink/">Black Ink</a> uses a number of keyed values describing its requirements:</p>
<pre>	&lt;key&gt;LSArchitecturePriority&lt;/key&gt;
	&lt;array&gt;
		&lt;string&gt;x86_64&lt;/string&gt;
		&lt;string&gt;i386&lt;/string&gt;
		&lt;string&gt;ppc&lt;/string&gt;
	&lt;/array&gt;
	&lt;key&gt;LSMinimumSystemVersion&lt;/key&gt;
	&lt;string&gt;10.4.0&lt;/string&gt;
	&lt;key&gt;LSMinimumSystemVersionByArchitecture&lt;/key&gt;
	&lt;dict&gt;
		&lt;key&gt;i386&lt;/key&gt;
		&lt;string&gt;10.4.0&lt;/string&gt;
		&lt;key&gt;x86_64&lt;/key&gt;
		&lt;string&gt;10.6.0&lt;/string&gt;
		&lt;key&gt;ppc&lt;/key&gt;
		&lt;string&gt;10.4.0&lt;/string&gt;
	&lt;/dict&gt;
</pre>
<p>Notice the fidelity of some of these options. Black Ink is an application that is compiled with binary code for three separate architectures embedded into it: 64-bit Intel, 32-bit Intel, and 32-bit PowerPC. In order to give the user the best possible experience after they double-click the application icon, the system consults the Info.plist values to determine which binary is most appropriate to load on the current system.</p>
<p>The options for Black Ink start by indicating that all things being equal, it prefers to run as 64-bit Intel, but will settle for 32-bit Intel or PowerPC in a pinch. Next, it conveys that it should not be run on any operating system earlier than Mac OS X 10.4. Finally, it adds an additional restriction by architecture, stating that in the case of 64-bit Intel, the system should consider Mac OS X 10.6 the minimum required OS.</p>
<p>Why so picky? For example, Mac OS X 10.5 will run on computers that are new enough to support 64-bit Intel code, but the 10.5 operating environment itself doesn&#8217;t contain enough compatible libraries to make it very useful to a full-featured Cocoa application. So we need to convince the 10.5 system <em>to ignore our 64-bit Intel code.</em> And this is how it&#8217;s done.</p>
<h3>Embedding Info.plist</h3>
<p>This is all well and good for applications, but what about other code that may be run on a variety of hardware and operating systems? In particular, command-line tools do not come in the same bundled-folder format that applications do. Fortunately, Apple thought of this when they implemented support in their developer tools for embedding the contents of an Info.plist directly into the binary itself. You just have to pass the Info.plist path to Apple&#8217;s linker tool when it&#8217;s constructing your binary file. (Thanks to <a href="http://www.noodlesoft.com/">Paul Kim</a> for reminding me of this functionality). What this means in practice is adding arguments like this to your Xcode target&#8217;s &#8220;Other Linker Flags&#8221; build setting:</p>
<pre>-sectcreate __TEXT __info_plist $(INFOPLIST_FILE)
</pre>
<p>This instructs the linker to crete a new text segment named &#8220;__info_plist&#8221; in the resulting binary, and to fill it with the contents of the referenced Info.plist file. To make sure the INFOPLIST_FILE expands correctly, just make sure you set it in the separate build setting for identifying the Info.plist (the one you&#8217;d normally use in an app, and that is just ignored by default for a command-line tool target).</p>
<p>I brushed up on all this information because I wanted to help ensure that some recent work I did to create a <a href="https://github.com/danielpunkass/peg-multimarkdown">standalone MultiMarkdown tool</a> would be backward compatible with older systems. This required <a href="https://github.com/danielpunkass/peg-multimarkdown/commit/ca523bac1fb03b9cfdcf540805e677086c063704">adding an embedded plist</a> much as I&#8217;m describing here.</p>
<p>(<strong>Note:</strong> I have gotten some feedback to the effect that the __info_plist segment&#8217;s minimum system version requirements may not actually be consulted properly on Mac OS X 10.5. This would be a bummer, and in fact sort of reject the whole point of embedding the Info.plist in this case. I&#8217;m going to see if I can confirm whether it doesn&#8217;t in fact work.)</p>
<p>You could technically embed all kinds of stuff in the binary, with different section names. But the contract in this case is that when Mac OS X is determining information about an executable, it will consult <strong>the bundle&#8217;s Info.plist file</strong>, if it happens to be an executable in a bundle, or <em>the binary&#8217;s __info_plist segment</em>, if it happens to have one.</p>
<p>Another common reason for needing to embed Info.plist information into a standalone binary is if you are using Apple&#8217;s code signing mechanism to sign an individual binary tool. Code signing uses information from the Info.plist of a product, and in the case of standalone binaries, the only product-cohesive place to put this is in the binary itself.</p>
<h3>Examining Binary Info.plists</h3>
<p>After you&#8217;ve performed the magic above, you&#8217;ll probably be keen to inspect your command-line tool&#8217;s Info.plist to see if it worked. To do this, you can use the otool command from the Finder. If you run otool with the &#8220;-l&#8221; option to show all load commands, it will include the load command that identifies the __info_plist segment. Use grep to narrow it down to the part you&#8217;re interested in:</p>
<pre>otool -l ./yourTool | grep info_plist -B1 -A10
</pre>
<p>Any results at will confirm that there is Info.plist information in the binary, but how does it look? The &#8220;-s&#8221; option to otool lets you examine the contents of a specific segment in a binary, but it dumps it out as hex code. Fortunately, another system-bundled tool called &#8220;xxd&#8221; is capable of easily converting between hex-dump and text formats. As it turns out, some of Apple&#8217;s bundled developer tools (at least on my Mac) contain these embedded __info_plist sections, so if you don&#8217;t have a command line tool of your own to try this on, you can peek at what the &#8220;atos&#8221; tool has to say for itself:</p>
<pre>otool -s __TEXT __info_plist /usr/bin/atos | xxd -r
</pre>
<h3>In Summary</h3>
<p>Info.plist values are important for conveying information about your product, from the crudest, most obvious stuff like version number, to the most nuanced details such as which architectures are supported. Knowing how to specify an application or tool&#8217;s requirements as precisely as possible will ensure that the product performs optimally on whatever supported system your user happens to be using. I&#8217;ve barely scratched the surface here with a few common deployment keys that control execution behavior on Mac OS X. Be sure to skim Apple&#8217;s <a href="http://developer.apple.com/library/mac/#documentation/General/Reference/InfoPlistKeyReference/Introduction/Introduction.html">Information Property List Key Reference</a> to see if there are other useful bits of information you can share for your application <em>or for your command-line tool.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.red-sweater.com/blog/2083/the-power-of-plist/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Usable Keychain Scripting For Lion</title>
		<link>http://www.red-sweater.com/blog/2035/usable-keychain-scripting-for-lion</link>
		<comments>http://www.red-sweater.com/blog/2035/usable-keychain-scripting-for-lion#comments</comments>
		<pubDate>Fri, 29 Jul 2011 19:15:43 +0000</pubDate>
		<dc:creator>Daniel Jalkut</dc:creator>
				<category><![CDATA[AppleScript]]></category>
		<category><![CDATA[Hacking]]></category>

		<guid isPermaLink="false">http://www.red-sweater.com/blog/?p=2035</guid>
		<description><![CDATA[I&#8217;m tracking down a mysterious behavior of Safari in Lion, where it seems to fail to enter my password for logins that I&#8217;ve saved to the keychain. In the process of looking into this, I noticed that &#8220;Keychain Scripting&#8221; has mysteriously disappeared from Lion. As far as I can tell you must copy Apple&#8217;s scripting addition [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m tracking down a mysterious behavior of Safari in Lion, where it seems to fail to enter my password for logins that I&#8217;ve saved to the keychain. In the process of looking into this, I noticed that &#8220;Keychain Scripting&#8221; has mysteriously disappeared from Lion. As far as I can tell you must copy Apple&#8217;s scripting addition from Snow Leopard in order to keep using it.</p>
<p>On the other hand, I wrote an alternative years ago, called <a href="http://www.red-sweater.com/blog/170/usable-keychain-scripting">Usable Keychain Scripting</a>. Its main advantage over Apple&#8217;s implementation is that it is (or at least, was) enormously faster. Today I updated the app to be 64-bit compatible and to fix a pernicious bug in which the password value returned for a keychain item would sometimes have garbage appended to the end of it.</p>
<p><a href="http://red-sweater.com/blog/downloads/UsableKeychainScripting.dmg">Download Usable Keychain Scripting 1.0b4</a></p>
<p>This is not a supported product, and your success with it may vary. But it has been very handy in the past for me, and hopefully it will come in handy for you if you need to script the keychain.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.red-sweater.com/blog/2035/usable-keychain-scripting-for-lion/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Picking Off iCal&#8217;s Paper Bits</title>
		<link>http://www.red-sweater.com/blog/1970/picking-off-icals-paper-bits</link>
		<comments>http://www.red-sweater.com/blog/1970/picking-off-icals-paper-bits#comments</comments>
		<pubDate>Sat, 23 Jul 2011 20:07:38 +0000</pubDate>
		<dc:creator>Daniel Jalkut</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Lion]]></category>
		<category><![CDATA[Rant]]></category>

		<guid isPermaLink="false">http://www.red-sweater.com/blog/?p=1970</guid>
		<description><![CDATA[OS X Lion brings dramatically redesigned versions of the classic iCal and Address Book applications. Many people, or at least some important decision makers inside Apple, are very happy with these changes. Other folks, such as myself, believe they look and behave like crap. When I first saw the Lion version of iCal, my eyes [...]]]></description>
			<content:encoded><![CDATA[<p>OS X Lion brings dramatically redesigned versions of the classic iCal and Address Book applications. Many people, or at least some important decision makers inside Apple, are very happy with these changes. Other folks, such as myself, believe they look and behave like crap.</p>
<p>When I first saw the Lion version of iCal, my eyes were drawn to the obnoxious bits of paper that cling to the top of the window, artificially and pointlessly leaving the debris that you might find on a real-life calendar with removable paper sheets:</p>
<p><img title="iCal-Messy.png" src="http://www.red-sweater.com/blog/wp-content/downloads/2011/07/iCal-Messy.png" border="0" alt="ICal Messy" width="450" height="192" /></p>
<p>As <a href="https://twitter.com/catshive">Cathy Shive</a> pointed out in her <a href="http://nsconference.com/">NSConference</a> talk on user interface metaphors, the presence of junk like this in an application is at best useless, at worst distracting and detrimental to the usability of the application. I remember her saying in her talk, before Lion&#8217;s iCal had even been presented in a private developer beta, that little things like paper scraps in an application are particularly annoying because she always wants to try to pick them off just as she would with a physical object.</p>
<p>Lion has given me the opportunity to empathize deeply with that concern. I hate those cruddy paper bits, and I can&#8217;t pick them off! Or can&#8217;t I?</p>
<p>To clean up your copy of iCal on Lion:</p>
<ol>
<li>Select the iCal application in the Finder and press cmd-D to duplicate (make a backup, for safe keeping).</li>
<li>Control click the application icon and select &#8220;Show Package Contents.&#8221;</li>
<li>Navigate to Contents/Resources/</li>
<li>Select &#8220;CanvasTopTile.png&#8221; and open it up in <a href="http://flyingmeat.com/acorn/">Acorn</a> or another, less attractive image editor. Or download <a href="http://www.red-sweater.com/blog/wp-content/downloads/2011/07/CanvasTopTile.png">my edited version</a> and replace the original file.</li>
<li>Select the paper bits and &#8220;clean them up&#8221; by deleting them.</li>
<li>Reopen iCal, and bask in the glow of your clean white calendar:</li>
</ol>
<p><img title="iCal-Clean.png" src="http://www.red-sweater.com/blog/wp-content/downloads/2011/07/iCal-Clean.png" border="0" alt="ICal Clean" width="450" height="197" /></p>
<p>Granted, this <em>only fixes the paper bits</em>. You&#8217;re still stuck with that horrendous tan leather toolbar. But at least that doesn&#8217;t beg to be picked at. It&#8217;s worth noting that the tan leather can also be tweaked by editing a variety of other image resources in the bundle. It&#8217;s trickier because many of the graphical components of the toolbar are designed to blend with the leather background, so you&#8217;ll end up having to change quite a few of the images.</p>
<p>I&#8217;m reminded of <em>another great observation</em> Cathy made in her talk: when you make very stylistic choices like this for a user interface, you dramatically increase the variety of reasons that the customer can be repulsed by the design. What if I don&#8217;t like leather? What if I don&#8217;t like <em>tan leather</em>? What if I prefer a <em>running stitch</em> to an <em>outline stitch</em>? You can argue that matte grays and subdued color gradients may invite the same controversy, but there&#8217;s a reason they are so common in user interfaces: because they&#8217;re far less likely to distract from the form and function of the application itself.</p>
<p><strong>Addendum: </strong><strong>Updating the iCal code signature</strong>. Thanks to <a href="https://twitter.com/rentzsch/status/94862617918717952">rentzsch</a> and <a href="https://twitter.com/daagaak/status/94867316520648704">daagaak</a> on Twitter for pointing out that editing the resource will break the &#8220;code signature&#8221; on the application, put there by Apple to assure users that the application 1. Was developed by Apple, and 2. Has not been modified by anybody but Apple. You can re-sign the application after tweaking it, to put it back into a  &#8221;signed&#8221; state, albeit not by Apple. Hopefully this will prevent it from prompting you all the time about approving connections to services like MobileMe. From the Terminal:</p>
<pre> codesign -f -s - /Applications/iCal.app</pre>
<p>This reveals how little things like tweaking an application&#8217;s resources have wider-reaching consequences than they used to. I&#8217;m pretty sure you won&#8217;t miss any functionality in iCal by using a self-signed copy of the app vs. an Apple-signed version. But I could be wrong!</p>
<ol> </ol>
]]></content:encoded>
			<wfw:commentRss>http://www.red-sweater.com/blog/1970/picking-off-icals-paper-bits/feed</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Bit Hacking</title>
		<link>http://www.red-sweater.com/blog/1947/bit-hacking</link>
		<comments>http://www.red-sweater.com/blog/1947/bit-hacking#comments</comments>
		<pubDate>Thu, 21 Jul 2011 14:28:37 +0000</pubDate>
		<dc:creator>Daniel Jalkut</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.red-sweater.com/blog/?p=1947</guid>
		<description><![CDATA[Lion is the first operating system to require, and to fully take advantage of, 64-bit addressing modes in the Intel chips that power Apple&#8217;s Macintosh computers. One of the side-effects of this is that every object identifier in Mac OS X&#8217;s Cocoa programming framework (typically an address in memory), is now twice as long as [...]]]></description>
			<content:encoded><![CDATA[<p>Lion is the first operating system to require, and to fully take advantage of, 64-bit addressing modes in the Intel chips that power Apple&#8217;s Macintosh computers. One of the side-effects of this is that every object identifier in Mac OS X&#8217;s Cocoa programming framework (typically an address in memory), is now twice as long as it was in a 32-bit environment.</p>
<p>Apple has apparently taken advantage of the 64-bit runtime in Lion by optimizing the Objective C runtime itself to use some of these extra bits for, shall we say, clever purposes. <a href="http://objectivistc.tumblr.com/">Bavarious describes an optimization</a> through which Apple is able to replace previously full-fledged opaque objects such as NSNumber with an object-placeholder that exists entirely as the 64-bit &#8220;object address&#8221; itself. This means that, for a wide range of &#8220;simple&#8221; objects, no additional memory allocation is required, and no retain/release memory management is required for the &#8220;object.&#8221;</p>
<p>The trick relies on a implementation detail of the system, that allocated blocks of memory will always be aligned at 16-byte offsets into the address space. This leaves a bunch of numbers that can be represented in 64-bits, that cannot reasonably be assigned to any other object. To understand this practically, imagine that your neighborhood&#8217;s postal addresses are all assigned at offsets of 10: 30, 40, 50, etc. A clever postal service could institute an addressing system that uses an &#8220;invalid&#8221; address such as &#8220;31,&#8221; to perhaps mean &#8220;deliver to 30 with expedited afternoon delivery.&#8221;</p>
<p>Cleverness like this with encoding extra information in memory addresses is a time-honored tradition. I recall the days of 24-bit addressing on classic Mac OS, where Apple, and many 3rd party developers, observed that the high 8 bits of a typical memory address could be tweaked and used to store additional information, because the system would never reference those bits when resolving a particular address.</p>
<p>In those days, using those extra bits turned out to be a pretty significant headache when 32-bit addressing ultimately came along, and lots of code had this &#8220;crufty&#8221; treatment of addresses to clean up. Perhaps it is a memory of situations like this that caused Jon &#8220;Wolf&#8221; Rentzsch to <a href="http://www.delicious.com/url/a01d14b2e7785507e55d15edf3a131d6">comment in his bookmarking</a> of the above-referenced blog post:</p>
<blockquote>
<p>&#8220;Every tagged pointer has its lowest bit set, hence tagged pointers are odd integers&#8221; <strong>Strikes me as a really bad idea. </strong>[Emphasis Mine]</p>
</blockquote>
<p>But the difference now, in this scenario, is the &#8220;cute hacking&#8221; is all being done by a central power, with and in terms of opaque objects that only Apple has the authority to change. I think this is a really clever hack that will undoubtedly lead to some serious performance gains in Lion and beyond. It&#8217;s hard to imagine specific outcomes that will make Apple regret adopting this strategy. In the worst case scenario, an addressing system of future Macs will not leave any &#8220;spare&#8221; bits to be exploited, so the runtime will simply revert to its previous behavior.</p>
<p> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.red-sweater.com/blog/1947/bit-hacking/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Get Lion</title>
		<link>http://www.red-sweater.com/blog/1924/get-lion</link>
		<comments>http://www.red-sweater.com/blog/1924/get-lion#comments</comments>
		<pubDate>Wed, 20 Jul 2011 14:10:38 +0000</pubDate>
		<dc:creator>Daniel Jalkut</dc:creator>
				<category><![CDATA[App Store]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Hacking]]></category>

		<guid isPermaLink="false">http://www.red-sweater.com/blog/?p=1924</guid>
		<description><![CDATA[Today Apple released OS X Lion, aka Mac OS X 10.7, the latest in the decade-long run of incredible updates to Mac OS X. I encourage everybody to upgrade to Lion. I&#8217;ve been running it for months in pre-release form, and even while the bugs were being ironed out, I found the experience of using it [...]]]></description>
			<content:encoded><![CDATA[<p>Today <a href="http://www.apple.com/macosx/">Apple released OS X Lion</a>, aka Mac OS X 10.7, the latest in the decade-long run of incredible updates to Mac OS X.</p>
<p>I encourage everybody to <a href="http://itunes.apple.com/us/app/os-x-lion/id444303913?mt=12">upgrade to Lion</a>. I&#8217;ve been running it for months in pre-release form, and even while the bugs were being ironed out, I found the experience of using it to be (mostly) superior to running 10.6.</p>
<p>If you want a more detailed analysis of Lion&#8217;s features, sit down with a tall glass of your favorite beverage, and read John Siracusa&#8217;s <a href="http://arstechnica.com/apple/reviews/2011/07/mac-os-x-10-7.ars">famously detailed review</a>. If you&#8217;re looking for a quicker overview, check out Jason Snell&#8217;s <a href="http://www.macworld.com/article/161026/2011/07/osx_lion_review.html">Macworld review</a>, or my developer buddy Matt Gemmell&#8217;s <a href="http://www.guardian.co.uk/technology/2011/jul/20/mac-osx-lion-review">guest appearance at the Guardian UK</a>.</p>
<h3>Supported Systems</h3>
<p>We have known for some time that Mac OS X Lion would drop support for a number of Macs. In particular, all Macs that do not support Intel&#8217;s 64-bit memory addressing are not qualified to install the OS. But I was curious to know a bit more about how Apple makes this determination when, say, a user is browsing the Lion &#8220;product&#8221; in the Mac App Store.</p>
<p>As I described <a href="http://www.red-sweater.com/blog/1566/the-future-of-mac-app-store-installs">in an an earlier post</a>, you can learn a lot about a product in the App Store by inspecting the HTML that makes up the product page, and by manually loading the references resources. In the case of Lion, the &#8220;Buy Now&#8221; button contains a number of parameters intended to inform the Mac App Store client about whether a sale should be allowed, and what some of the conditions of sale are. In the case of Lion, here is the raw HTML:</p>
<pre style="font-size: 1em; white-space: pre-wrap;">&lt;button is-rental="0" dk-id="30" is-pre-order="0" preflight="http://a5.mzstatic.com/us/r1000/
065/Purple/cd/82/29/mzm.tvvarwmu.pfpkg" item-name="OS X Lion" bundle-id="com.apple.InstallAssistant.Lion" version-string="10.7" buyparams="productType=C&amp;amp;price=0&amp;amp;salableAdamId=444303913&amp;amp; pricingParameters=STDRDL" large-icon="http://a4.mzstatic.com/us/r1000/083/Purple/00/00/00/ lion.170x170-75.png" is-install-button="0" is-update="0" check-is-osx-server="http://r.mzstatic.com/static/isOSXServer.pfpkg" is-free-download="0" adam-id="444303913" metrics-leaf="1" metrics-loc="Buy" class="button-area" aria-label="Install, OS X Lion, Free"&gt;    &lt;span class="price"&gt;Install&lt;/span&gt;    &lt;span class="left-cap"&gt;&lt;/span&gt;    &lt;div class="inner"&gt;&lt;span&gt;Install&lt;/span&gt;&lt;/div&gt;    &lt;span class="right-cap"&gt;&lt;/span&gt;  &lt;/button&gt;</pre>
<p>If you load the &#8220;preflight&#8221; URL content from the command line, and unarchive it with the &#8220;xar&#8221; tool, you get a few files including a file called &#8220;Distribution&#8221;:</p>
<pre style="font-size: 1em; white-space: pre-wrap;">% mkdir TestFolder; cd TestFolder
% curl -O http://a5.mzstatic.com/us/r1000/065/Purple/cd/82/29/mzm.tvvarwmu.pfpkg
% xar -x -f mzm.tvvarwmu.pfpkg
% more Distribution
</pre>
<p>Inside you will see a number of constant constraints such as <strong>hostArchitectures=&#8221;x86_64,i386&#8243;</strong>, but also more nuanced tests that, for example, test the current computer&#8217;s motherboard model ID with a fixed list of allowed values. Presumably this will prevent the App Store from allowing (without some hacking) downloading Lion and installing it, for example, on a Dell PC that happens to meet the ostensive hardware requirement.</p>
<p>Perhaps the most heartwarming bit of code in this relatively complex document is a small function call from the start of the test for whether the install should be allowed on this computer:</p>
<pre style="font-size: 1em; white-space: pre-wrap;">function isSupportedPlatform(){

        if( isVirtualMachine() ){
                return true;
        }
</pre>
<p>It has already been announced that Lion 10.7 will finally support virtualization, e.g. with the use of products such as VMWare or Parallels. This install-time test seems to drive home how true that is.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.red-sweater.com/blog/1924/get-lion/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Future Of Mac App Store Installs</title>
		<link>http://www.red-sweater.com/blog/1566/the-future-of-mac-app-store-installs</link>
		<comments>http://www.red-sweater.com/blog/1566/the-future-of-mac-app-store-installs#comments</comments>
		<pubDate>Fri, 07 Jan 2011 21:49:28 +0000</pubDate>
		<dc:creator>Daniel Jalkut</dc:creator>
				<category><![CDATA[App Store]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Macintosh]]></category>

		<guid isPermaLink="false">http://www.red-sweater.com/blog/?p=1566</guid>
		<description><![CDATA[It&#8217;s only been one day since the launch of the Mac App Store, and the Mac developer and user communities are buzzing with consequences, both good and bad, of the store and how it operates. One particularly vexing issue is the question of whether an app that is already on your Mac is &#8220;installed&#8221; or [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s only been one day since the <a href="http://www.red-sweater.com/blog/1559/the-mac-app-store">launch of the Mac App Store</a>, and the Mac developer and user communities are buzzing with consequences, both good and bad, of the store and how it operates.</p>
<p>One particularly vexing issue is the question of whether an app that is already on your Mac is &#8220;installed&#8221; or not in the eyes of the App Store application. Dan Moren of Macworld <a href="http://www.macworld.com/article/156980/2011/01/installed_apps_appstore.html">presents a great summary</a> of the situation.</p>
<p>In a nutshell: if App Store thinks an app is installed, it&#8217;s impossible to buy it. If App Store thinks an app is installed, but it&#8217;s not really from the App Store, there&#8217;s a risk of repurchasing something that you already own a license for.</p>
<p>What this brings into focus is the very problematic nature of that small multi-purpose button the App Store, that allows for either buying an app you don&#8217;t own, or for linking to an app that you do own:</p>
<p><img style="border-color: #aaa;" src="http://www.red-sweater.com/blog/wp-content/downloads/2011/01/App-Store-2.jpg" border="1" alt="App Store-2.jpg" width="450" height="186" /></p>
<p>As it happens, the App Store user interface is implemented primarily in HTML. Using a surprisingly under-appreciated feature of WebKit, the omnipresent web inspector, I was able to look behind the scenes at some of the interesting HTML that supports this Buy/Installed button. For Black Ink&#8217;s button above, this is what I see:</p>
<pre>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px monospace; color: #977d40;"><span style="color: #c22a9c;">&lt;button </span>version-string<span style="color: #c22a9c;">=</span><span style="color: #d92823;">"1.2.3"</span><span style="color: #c22a9c;"> </span>is-rental<span style="color: #c22a9c;">=</span><span style="color: #d92823;">"0"</span><span style="color: #c22a9c;"> </span>is-pre-order<span style="color: #c22a9c;">=</span><span style="color: #d92823;">"0"</span><span style="color: #c22a9c;"> </span>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px monospace; color: #d92823;"><span style="color: #977d40;"><span style="color: #000000;"><span style="font-size: medium;">   </span></span></span><span style="color: #977d40;">buy-params</span><span style="color: #c22a9c;">=</span>"productType=C&amp;amp;price=24990&amp;amp;
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px monospace; color: #d92823;"><span style="color: #000000;"><span style="font-size: medium;">                 </span></span>salableAdamId=402376365&amp;amp;pricingParameters=STDQ"
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px monospace; color: #223cf5;"><span style="color: #977d40;"><span style="color: #c22a9c;">   </span></span><span style="color: #977d40;">preflight</span><span style="color: #c22a9c;">=</span><span style="color: #d92823;">"<a href="http://a1757.phobos.apple.com/us/r1000/057/Purple/e7/fb/12/mzm.gytejomu.pfpkg"><span style="color: #223cf5;">http://a1757.phobos.apple.com/us/r1000/</span></a></span><span style="color: #d92823;"><span style="color: #223cf5;">
                 <a href="http://a1757.phobos.apple.com/us/r1000/057/Purple/e7/fb/12/mzm.gytejomu.pfpkg">057/Purple/e7/fb/12/mzm.gytejomu.pfpkg</a></span>"</span><span style="color: #c22a9c;"> </span>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px monospace; color: #977d40;"><span style="color: #c22a9c;">   </span>is-install-button<span style="color: #c22a9c;">=</span><span style="color: #d92823;">"0"</span>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px monospace; color: #223cf5;"><span style="color: #977d40;"><span style="color: #c22a9c;">   </span></span><span style="color: #977d40;">large-icon</span><span style="color: #c22a9c;">=</span><span style="color: #d92823;">"<a href="http://a1.phobos.apple.com/us/r1000/013/Purple/74/8c/bb/mzi.wpgwhzjm.170x170-75.png"><span style="color: #223cf5;">http://a1.phobos.apple.com/us/r1000/013/</span></a></span>
<span style="color: #d92823;"><span style="color: #223cf5;">                 <a href="http://a1.phobos.apple.com/us/r1000/013/Purple/74/8c/bb/mzi.wpgwhzjm.170x170-75.png">Purple/74/8c/bb/mzi.wpgwhzjm.170x170-75.png</a></span>"</span><span style="color: #c22a9c;"> </span>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px monospace; color: #977d40;">   is-update<span style="color: #c22a9c;">=</span><span style="color: #d92823;">"0"</span><span style="color: #c22a9c;"> </span>item-name<span style="color: #c22a9c;">=</span><span style="color: #d92823;">"Black Ink"</span><span style="color: #c22a9c;"> </span>adam-id<span style="color: #c22a9c;">=</span><span style="color: #d92823;">"402376365"</span><span style="color: #c22a9c;"> </span>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px monospace; color: #977d40;">   is-free-download<span style="color: #c22a9c;">=</span><span style="color: #d92823;">"0" </span><span style="color: #d92823;"><span style="color: #977d40;">bundle-id</span><span style="color: #c22a9c;">=</span>"com.red-sweater.blackink.macappstore"</span>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px monospace; color: #977d40;"><span style="color: #d92823;"><span style="color: #977d40;">   metrics-leaf</span><span style="color: #c22a9c;">=</span>"1"<span style="color: #c22a9c;"> </span><span style="color: #977d40;">metrics-loc</span><span style="color: #c22a9c;">=</span>"Buy" </span><span style="color: #d92823;"><span style="color: #977d40;">title</span><span style="color: #c22a9c;">=</span>"Buy, Black Ink: $24.99"</span>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px monospace; color: #977d40;"><span style="color: #d92823;"><span style="color: #977d40;">   disabled</span><span style="color: #c22a9c;">=</span>""<span style="color: #c22a9c;"> </span><span style="color: #977d40;">its-bound</span><span style="color: #c22a9c;">=</span>"iTSBuyButton"<span style="color: #c22a9c;">&gt;</span></span>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px monospace; color: #c22a9c;"><span style="color: #000000;"><span style="font-size: medium;">   </span></span>&lt;span <span style="color: #977d40;">class</span>=<span style="color: #d92823;">"price"</span>&gt;&lt;/span&gt;
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px monospace;"><span style="color: #c22a9c;"><span style="font-size: medium;">   </span></span><span style="color: #c22a9c;">&lt;span </span><span style="color: #977d40;">class</span><span style="color: #c22a9c;">=</span><span style="color: #d92823;">"action"</span><span style="color: #c22a9c;">&gt;</span>Installed<span style="color: #c22a9c;">&lt;/span&gt;</span>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px monospace; color: #c22a9c;">&lt;/button&gt;
</pre>
<p>Formatting XML, even with a cool app like <a href="http://www.red-sweater.com/marsedit/">MarsEdit</a>, is still a huge pain. I&#8217;ve tried to make it readable here so you can enjoy some of the interesting tidbits in this markup. There are some tantalizing attributes like <strong>is-update</strong> and <strong>is-free-download</strong>, which might lead some of us to imagine whether a paid update may be a configuration away. There&#8217;s some hocus-pocus sale parameters which surely mean something to iTunes on the other end of the network connection, and there&#8217;s a link to the application&#8217;s pretty icon.
</p>
<p style="padding:1em; border-style:solid; border-width:1px; border-color:#aaa;">Wondering about that global web inspector trick? Any application that has the NSUserDefaults key <strong>WebKitDeveloperExtras</strong> defined to YES receives access to the sexy WebKit web inspector that is so awesomely utilized in Safari. You can define this for the App Store app by running this from the command line in a Terminal window: <strong>defaults write com.apple.appstore WebKitDeveloperExtras -bool true</strong> Make sure you quit App Store before you run it, then relaunch it.
</p>
<h3>But What&#8217;s Really Interesting&#8230;</h3>
<p>All of this is fun to poke around at, but what I find fascinating is the <strong>preflight</strong> attribute, which points to a mysterious asset on the web. This &#8220;.pfpkg&#8221; file, which as it turns out is simply <a href="http://code.google.com/p/xar/">xar</a> archive format, contains an interesting file called <strong>Distribution</strong>, an XML-formatted file that contains rules and attributes for how the application should be installed, how the App Store should locate an &#8220;Installed&#8221; app on the user&#8217;s Mac, etc. I&#8217;m not going to the trouble of color formatting this one, but have a look in a separate window:</p>
<p><a href="http://red-sweater.com/blog/wp-content/downloads/2011/01/BlackInkPreflight.txt">View Black Ink&#8217;s Preflight Rules</a></p>
<p>I believe the format for this XML document is either completely or partially tied up in the way the Mac OS X Installer packages work. I have been lucky enough in my lifetime not to have to do all that much with installer packages, so I am not sure exactly how to parse the whole file. It&#8217;s clear however, that the file contains information about the application, its version and bundle identifier. It also contains similar information for each of the frameworks that ships with the application.</p>
<p>But the interesting stuff begins below that, where we see flags such as <strong>customize=no</strong>, and an alluring <strong>volume-check</strong>, which seems to be terminology from Installer-land that alludes to installers being able to determine whether the targeted volume is suitable for installation.</p>
<p>As you can see, the Black Ink preflight document is pretty boring. No, there is no customize flag. No, there are no interesting volume-check attributes, aside from the fact that this requires 10.6.6, like every other dang app on the Mac App Store. Yawn.</p>
<p>I decided to take a look at another application in the App Store. One that, if anything was going to be interesting, surely this one would be.</p>
<p>
<img style="border-color: #aaa;" border="1" src="http://www.red-sweater.com/blog/wp-content/downloads/2011/01/App-Store-3.jpg" alt="App Store-3.jpg" border="0" width="450" height="204" /></p>
<p>One of the things I keep reminding myself, when trying to deduce what Apple&#8217;s plans are for a variety of &#8220;would be nice&#8221; features in the App Store, such as upgrades, trials, etc., is &#8220;how does the current setup inconvenience Apple itself?&#8221; Many of Apple&#8217;s apps are shipped for free with the system and are updated for free along with OS updates. But others are not: iLife and iWork are sold in a bundle with no upgrade pricing, and other apps such as Final Cut Pro and Logic have complicated pricing, which perhaps explains why they aren&#8217;t on the App Store at all. But Aperture falls right in the middle: fairly straight-forward pricing, but it&#8217;s expensive enough that they offer reasonable upgrade charges for users who already own a license. Maybe there will be something interesting in these <strong>preflight rules</strong>:</p>
<p><a href="http://red-sweater.com/blog/wp-content/downloads/2011/01/AperturePreflight.txt">View Aperture&#8217;s Preflight Rules</a></p>
<p>The file length alone indicates that something slightly more complicated is going on, and my eyes are drawn immediately to the JavaScript code in the middle of the document, and a function named <strong>shouldAllowPurchaseAndInstall()</strong>. Hmm, you mean there&#8217;s a choice? Usually what happens when you click &#8220;Buy&#8221; in the App Store, is you are prompted to login if necessary, and then you are warned that this is going to cost you money, it&#8217;s a big deal, etc. But as far as I can tell, a side-effect of clicking <strong>Buy</strong> in the App Store is that the aforementioned volume-check is also run on the target system, giving App Store one last chance to bail out of the process before something unfortunate is done.</p>
<p>In Aperture&#8217;s case, you can see by the nicely commented script that it takes care to only allows the <strong>Buy</strong> order to go through under certain circumstances. In making this determination, it checks all of the installed copies of Aperture on the system, looking for signs of App Store purchase such as the presence of a &#8220;_MASReceipt&#8221; inside the app. It also takes care to differentiate between different versions of Aperture, failing in some cases with a specific string that is presumably passed along to the App Store user.</p>
<p>If you&#8217;ve managed to follow along this far, you&#8217;re probably putting two and two together and realizing that the technology exists today for applications to avoid at least one of the problems mentioned above: the inadvertent redundant purchase that may happen when a user thinks it&#8217;s safe to buy an app, because &#8220;they already have a license.&#8221;</p>
<p>The preflight XML document may be documented in part or in full in the context of Mac OS X Installer Packages, but as far as I know, none of this is documented in the context of the Mac App Store. I do not know if any 3rd party developer has been invited to use this technique, or if it&#8217;s something we could just put into our installer packages somehow on our own, and hope for the best.</p>
<p>What&#8217;s most interesting about all this is that there is clearly an infrastructure in place for allowing a wide variation of behaviors, all centering around the multi-purpose Buy/Installed button in the App Store. I would like to see the <strong>volume-check</strong> options documented and made explicitly available to developers, so that we can help prevent unwanted redundant purchases on the part of our customers. I would also be curious to know if other hooks are in place or are planned to for example allow developers whose apps <em>do show up as installed</em> to second-guess that assumption and encourage the App Store to provide a &#8220;Buy&#8221; option to customers.</p>
<p>Where we&#8217;re going, only Apple knows, but I thought the details I discovered in this nook of the App Store app offer some interesting clues. I&#8217;m also interested in sharing this because I believe that the more we understand about the App Store install process, the better we&#8217;ll be able to offer meaningful enhancement requests to Apple. &#8220;Support paid upgrades&#8221; and &#8220;Allow variable behavior depending on installed apps&#8221; are fine feature requests, but if we are able to put them into the context of what Apple already knows is possible, they may be more likely to get implemented.</p>
<p>If anybody else has delved into the underbelly of the App Store and has observations to share, please do so in the comments, or with a link to your own blog article on the subject.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.red-sweater.com/blog/1566/the-future-of-mac-app-store-installs/feed</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Hold On A Minute</title>
		<link>http://www.red-sweater.com/blog/1397/hold-on-a-minute</link>
		<comments>http://www.red-sweater.com/blog/1397/hold-on-a-minute#comments</comments>
		<pubDate>Thu, 09 Sep 2010 18:00:18 +0000</pubDate>
		<dc:creator>Daniel Jalkut</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Macintosh]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.red-sweater.com/blog/?p=1397</guid>
		<description><![CDATA[One of the big new features in MarsEdit 3 is a revamped media manager that allows you to easily browse local libraries from iPhoto, Aperture, etc. This functionality is based largely on the great work of the iMedia project, which was spearheaded by Karelia to replicate Apple&#8217;s own ubiquitous media browsing interface, some variant of [...]]]></description>
			<content:encoded><![CDATA[<p>One of the big new features in <a href="http://www.red-sweater.com/marsedit/">MarsEdit 3</a> is a revamped media manager that allows you to easily browse local libraries from iPhoto, Aperture, etc.</p>
<p><img src="http://www.red-sweater.com/blog/wp-content/downloads/2010/09/Media-Manager.png" alt="Media Manager.png" border="0" width="450" height="371" /></p>
<p>This functionality is based largely on the great work of the <a href="http://code.google.com/p/imedia/">iMedia</a> project, which was spearheaded by <a href="http://www.karelia.com/">Karelia</a> to replicate Apple&#8217;s own ubiquitous media browsing interface, some variant of which is available in Pages, iWeb, Mail, etc.</p>
<p>iMedia has been around for a while, but in the past year or more it has been undergoing a significant overhaul as its primary developers gear up to release the official 2.0 milestone. I have been involved in the 2.0 project for a long time now as an &#8220;early adopter,&#8221; using MarsEdit as a testing ground during the beta phase, and taking (mostly!) only the refined and polished aspects of the product for the final MarsEdit 3.0 release.</p>
<p>We are still ironing out some of the kinks, especially in parts of the project that were not tested in MarsEdit. One of the cool new features is support for the Flickr photo-sharing service. Like MarsEdit&#8217;s own Flickr-browser, it shows thumbnails of images on Flickr, and lets you treat them more-or-less like ordinary image files that you&#8217;d find on your computer.</p>
<p><img src="http://www.red-sweater.com/blog/wp-content/downloads/2010/09/iMedia2.png" alt="iMedia Flickr Support" border="0" width="450" height="344" /></p>
<p>Things get a little bit complicated when a user selects and drags one of these Flickr image thumbnails to another app, such as the Finder, or Photoshop. Since the image lives in the internet, and not on the local hard disk, it is not something that can be popped over to the application in an instant. Instead, a progress dialog comes up while the image is downloaded to the disk, and then the local copy is passed to the receiving application.</p>
<p><img src="http://www.red-sweater.com/blog/wp-content/downloads/2010/09/iMediaFlickr.png" alt="iMedia Flickr Download Panel" border="0" width="400" height="188" /></p>
<p>I try to contribute back when possible in the form of bug fixes and architectural feedback. Some of the work I did for iMedia 2.0 involved updating its drag-and-drop functionality to take advantage of new features in Mac OS X 10.6. In the process, I became a sort of de facto expert on handling dragging, which is a shame, because we could sure use a <em>real</em> expert, instead!</p>
<p>The other day, an issue came up that relates to the dragging of Flickr files. If the download is taking a while, and the user tries to cancel, mouse clicks are apparently ignored and they are stuck with the progress dialog above. I agreed to look into the issue, but there was just one problem: my network is too fast! Whenever <em>I</em> try to drag a Flickr image to another app, it&#8217;s done within a couple seconds, and I don&#8217;t have time to play around with clicking the cancel button.</p>
<p>If only I could get a <em>really slow connection</em> to Flickr, then I could easily test this. In the old days of Mac OS 9 or earlier, I may have resorted to plugging in a slow modem to simulate the experience of the less bandwidth-fortunate. In Mac OS X however, I can take advantage of the advanced firewall software that comes bundled with the operating system, and which allows me to configure &#8220;traffic shaping&#8221; policies on the traffic coming in and out of my computer. I found a great <a href="http://hints.macworld.com/article.php?story=20080119112509736">hint from Macworld</a> that got me on the right track.</p>
<p>My goal is to cause Flickr downloads to be artificially slow. In order to achieve this goal I need to find the specific web address that the downloads come from. To do this, I use the standard tcpdump terminal utility, which also comes bundled with Mac OS X:</p>
<pre>
sudo tcpdump -Atqp -s 0 -ien1
</pre>
<p>The only part you may want to change is the bit at the end that says &#8220;en1&#8243;. Depending on the network interface you&#8217;re using, you might want en0 or en2 instead. With this running in the terminal, I go back to iMedia and start downloading Flickr files. This lets me see what the addresses of those files look like, and I discover the pertinent host name is &#8220;farm5.static.flickr.com&#8221;. Using the information I gleaned from the Macworld article, I set up the following firewall traffic shaping rules:</p>
<pre>
sudo ipfw pipe 1 config bw 15KByte/s
sudo ipfw add 1 pipe 1 src-port 80 src-ip farm5.static.flickr.com
</pre>
<p>Translation?</p>
<ol>
<li>Create a pipe (you might prefer to call it a &#8220;tube&#8221;). A pipe is an artificial pass-through which can be configured to slow down, block, or otherwise alter the network traffic that goes through it.</li>
<li>Configure the pipe to limit bandwidth to a crawling 15KByte/s.</li>
<li>Configure all traffic coming from port 80 (the standard HTTP port), and originating from a specific hostname at Flickr, to pass through that pipe.</li>
</ol>
<p>As soon as these commands are executed, the pipe is in place, and Flickr download speeds are brought to screeching halt. I can now debug the issue with the download dialog and the cancel button patiently and curiously, instead of racing to try clicking the button while I still have the chance.</p>
<p>When I&#8217;m done debugging, I definitely want to delete the pipe, so that download speeds go back to normal:</p>
<pre>
sudo ipfw delete 1
</pre>
<p>Mucking around with the built-in firewall on Mac OS X is not for the extremely faint-of-heart. This is why all the commands listed in this entry require &#8220;sudo&#8221; superuser privileges. Yes, you could seriously screw up your computer&#8217;s network connection if you do something wrong. But if you are the type of person whose work requires you to test and debug network related tasks, this traffic shaping functionality can be a real asset when it comes to mimicking the network environments of other people.</p>
<p><strong>Addendum:</strong> I should have known I might be doing it the hard way, as usual. Clint Ecker <a href="http://twitter.com/clint/status/24032579293">reported on Twitter</a>, and several folks in the comments below, that <a href="http://mschrag.github.com/">speedlimit</a>, a Mac OS X preference pane, gets the job done in a much friendlier manner.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.red-sweater.com/blog/1397/hold-on-a-minute/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Getting Pretty Lonely</title>
		<link>http://www.red-sweater.com/blog/825/getting-pretty-lonely</link>
		<comments>http://www.red-sweater.com/blog/825/getting-pretty-lonely#comments</comments>
		<pubDate>Thu, 02 Jul 2009 18:09:48 +0000</pubDate>
		<dc:creator>Daniel Jalkut</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Rant]]></category>

		<guid isPermaLink="false">http://www.red-sweater.com/blog/?p=825</guid>
		<description><![CDATA[This very post is delivered to your browser or news reader by the famous and fabulous WordPress blogging system. In my work as the developer of MarsEdit, I am exposed to countless blogging options, each with its own strengths and weaknesses. And yet, I stick with WordPress because it strikes a balance of power and [...]]]></description>
			<content:encoded><![CDATA[<p>
This very post is delivered to your browser or news reader by the famous and fabulous <a href="http://wordpress.org/">WordPress</a> blogging system. In my work as the developer of <a href="http://www.red-sweater.com/marsedit/">MarsEdit</a>, I am exposed to countless blogging options, each with its own strengths and weaknesses. And yet, I stick with WordPress because it strikes a balance of power and ease of use which feels comfortable to me. Not to mention that <a href="http://josephscott.org/">Joseph Scott</a> and others are tirelessly working to improve its API.
</p>
<p>
WordPress is licensed under the terms of the <a href="http://www.gnu.org/licenses/quick-guide-gplv3.html">Gnu Public License</a> (GPL) which, in a nutshell, stipulates that you are free to use the software however you like, but if you make changes and <em>distribute</em> those changes, then you must share those changes under the same terms. This simple, radical restriction means that you are prohibited from taking a GPL project and incorporating it with a closed-source project.
</p>
<p><h3>Violating The GPL</h3>
</p>
<p>
Violating the GPL is easy. All you have to do is write some code,  intermingle it with some GPL code, distribute a changed copy of the original, and refuse to share your contributions. Bam! You&#8217;re toast. Assuming the original authors discover your violation and decide to pursue a resolution.
</p>
<p>Once a violation occurs, it might be settled privately, or could escalate to legal court procedures. But the most obvious form of resolution is for the author of the changes to release their code to the public under the terms of the GPL.
</p>
<p>
Depending on how much code you &#8220;mixed&#8221; with the GPL code, this could mean only a small portion, or it could mean the entire source code of your project. This so-called &#8220;viral nature&#8221; of GPL is what scares the bejeezus out of companies, large and small, who fear the consequences of having to give up their own intellectual property to the public.
</p>
<p>
The terms of the GPL sound pretty simple at first read, but due in part to the epic consequences of a violation, there has been a great deal of debate and uncertainty about what legally constitutes a violation. Most of the debate seems to boil down to two questions:
</p>
<p><ol>
<li>What counts as a change to the original product?</li>
<li>What counts as distribution of those changes?</li>
</ol>
<p>If you can legally justify that your additions to a GPL project either <em>don&#8217;t change or derive from</em> the original product, or haven&#8217;t technically been <em>distributed</em>, then you are not subject to the restrictive terms of the license.
</p>
<p>
Take <a href="http://www.gimp.org/">GIMP</a>, the popular GNU-licensed image editing application. The application supports plugins, analogous to the types of plugins you might find for the commercial, closed-source application Photoshop. A savvy developer may argue that a plugin doesn&#8217;t meet the criteria of changing the original application, because the original application still runs in its unaltered condition whether the plugin is there or not.
</p>
<p>
But promoters of the GPL take the position that plugins, by nature of being loaded into the same code space as other GPL code, do constitute a modification of the original, and are therefore subject to the terms of the GPL. As far as I know this is not a question that has been well-tested in courts.
</p>
<p>
Let me take a moment to make this abundantly clear: <strong>I respect the rights of authors to license their software under whatever terms they choose, including the GPL.</strong> In my opinion, all the legal mumbo jumbo ceases to matter once the original author&#8217;s <em>intentions</em> are made clear. So if the author of GPL-licensed code clarifies to me that it cannot be run on Sundays, then <em>their GPL</em> means it cannot be run on Sundays. But this is one of the   problems with the GPL: its terms are not often understood, even by the authors of GPL-licensed code.
</p>
<p><h3>WordPress Themes &#038; Plugins</h3>
</p>
<p>
WordPress supports two explicit forms of extension, each of which may affect the appearance and functionality of the product. Themes tend to work as a &#8220;skin&#8221; for the appearance of a blog, while plugins tend to introduce completely new features. Since plugins in WordPress are analogous to GIMP or Photoshop plugins, it would stand to reason that they would also be covered by the terms of the GPL. But what about themes?
</p>
<p>
Themes have been controversial in the WordPress community, as a few commercial business models have sprung up to take advantage of bloggers&#8217; desires for high quality themes at an affordable price. One approach is to distribute &#8220;free&#8221; themes that contains commercial ads. So you might stumble upon the perfect theme for your blog, only to learn that the glaring &#8220;Brought to you by Hostess Cupcakes&#8221; line near the bottom of your page cannot be removed.
</p>
<p>
But the terms of the GPL, if themes are covered, would require that end users be granted the legal right to modify and redistribute their own copy of the theme. Zap the sponsorship, reupload to your site, and you&#8217;ve got a free, high quality theme with no ugly ads.
</p>
<p>
Today, Matt Mullenweg of the WordPress project announced his lawyer-supported opinion that <a href="http://wordpress.org/development/2009/07/themes-are-gpl-too/">themes are partly covered by the GPL</a>:
</p>
<blockquote><p>
I reached out to the Software Freedom Law Center, the world’s preeminent experts on the GPL, which spent time with WordPress’s code, community, and provided us with an official legal opinion. One sentence summary: PHP in WordPress themes must be GPL, artwork and CSS may be but are not required.
</p></blockquote>
<p>If you&#8217;re starting with the understanding that WordPress itself is GPL, and WordPress plugins are GPL, then it&#8217;s not so much extra hay on the camel&#8217;s back, to also clarify that its themes are to some extent GPL. But it got me thinking again about my own blog, and about the restrictions the GPL imposes on the kinds of things I can do with the software that runs it.</p>
<p><h3>GPL Stifles Participation</h3>
</p>
<p>
Now for the most controversial point of this article, where I suggest that the GPL does more to harm collaborative development than it does to help it.
</p>
<p>
For the purposes of this argument, let me reduce all the source code in the world down to three rough categories. I recognize I have omitted some classes of license here, but for the sake of argument, most projects fall into these camps:
</p>
<p><ol>
<li>GPL code. Changes may be distributed only in other GPL products.</li>
<li>Liberal-licensed code. (MIT/BSD/Apache/etc). Changes may be distributed anywhere. Appropriate origin-attribution may be required.</li>
<li>Closed-source code. May be distributed only by the copyright owner and other explicit licensees.</li>
</ol>
<p>
Now, there are a few people in the world who, for political or philosophical reasons, will <em>only</em> participate in a GPL project. And for comparable yet opposite reasons, there are some who will <em>only</em> participate in commercial, closed-source projects. But I propose that <strong>the vast majority of developers will participate in any project that is advantageous to them.</strong>
</p>
<p>
So let&#8217;s imagine a representative, run-of-the-mill developer who is working on a project that falls into each of these three camps. If this developer is not radically committed to their own project&#8217;s license, they will naturally look to outside resources in order to bolster the success of their own work.</p>
</p>
<p>
As the developer evaluates communities to participate in, they must evaluate the legal impact such participation will have on their own project. The closed source communities are, by definition uninviting to outsiders. GPL communities are open and embracing of other GPL developers, but generally off-putting to liberal-license and closed-license developers. <strong>Only the liberal-license communities are attractive to developers from all 3 camps.</strong>
</p>
<p>
I know what some of the GPL-enthusiasts are thinking now: &#8220;leeches don&#8217;t count as community.&#8221; Many GPL developers  take comfort in the fact that their hard work can&#8217;t be quietly taken and incorporated into a commercial product, without any payback of time or money to the original project. But you&#8217;re piloting an open source project, and the first step of building a community is to get people in the door. Liberal licenses? Whoo-eee do they ever get people in the door.
</p>
<p>
If you operate from the presumption that great developers love to build great projects, the first step in any successful open source project is to get as many great developers in the door as possible.
</p>
<p><h3>It&#8217;s Your Party</h3>
<p>Yes, this is just me and my crazy theories. I haven&#8217;t done exhaustive research to prove that liberal-license communities thrive more than GPL communities. But the anecdotal examples are staggering. The very foundation of Mac OS X, the operating system through which I&#8217;m typing, is thanks to the liberally-licensed <a href="http://www.freebsd.org/">FreeBSD</a> operating system.
</p>
<p>
Looking over to the right of my screen, I&#8217;m watching this sentence appear in a live web preview as I type, thanks to the <a href="http://webkit.org/">WebKit</a> project, whose liberal license makes it compatible with closed source projects such as Safari, as well as open source efforts such as Google&#8217;s <a href="http://code.google.com/chromium/">Chromium</a> project.
</p>
<p>
For years, the problem of a generic HTTP client library that runs on every major platform has been addressed by <a href="http://curl.haxx.se/libcurl/">libcurl</a>, whose liberal license has caused it to be embraced by <em>countless</em> <a href="http://curl.haxx.se/docs/companies.html">companies</a> and <a href="http://curl.haxx.se/libcurl/using/apps.html">projects</a>.
</p>
<p>
The popular <a href="http://subversion.tigris.org/">Subversion</a> source control system&#8217;s liberal license enabled <a href="http://www.madebysofa.com/">Sofa</a>, a commercial software business to contribute value to the community with its extremely polished, <a href="http://versionsapp.com/">award-winning client application</a>. Meanwhile, the newly popular distributed source control systems presents three major choices: <a href="http://git-scm.com/">git</a>, <a href="http://mercurial.selenic.com/wiki/">Mercurial</a>, and <a href="http://bazaar-vcs.org/">Bazaar</a>. All are restricted by the GPL-license, and therefore none is likely to inspire development of a Versions-caliber client.
</p>
<p>
I&#8217;ve touched the tip of the iceberg, and yes I&#8217;ve neglected to mention some GPL success stories such as <a href="http://linux.org/">Linux</a>, <a href="http://www.mysql.com/">MySQL</a>, and <a href="http://gcc.gnu.org/">gcc</a>. These communities have thrived to some extent because the passions of the GPL community are strong, but we can&#8217;t know whether their success is <em>in spite of</em> the restrictions their license places on participation by the broader developer community.
</p>
<p>
Speaking of GPL succeses, WordPress is itself an example of <em>monumental success.</em> All of its developers have something to be immensely proud of. But whenever I am reminded that WordPress is GPL, my passion for it takes a bit of a dive. I&#8217;m more comfortable with the true freedom of liberally-licensed products. If a liberally-licensed blog system of equal quality, ease of use, and popularity should appear, my loyalties to WordPress would not last long.
</p>
<p>
It&#8217;s your party, and you&#8217;re entitled to write the guest list. But take a look around the room: not as many folks as you&#8217;d hoped for? Liberally-licensed projects are booming. Speaking for myself, a developer who has been to <em>all the parties</em>, I&#8217;m much more likely to pass through the door that doesn&#8217;t read &#8220;GPL Only.&#8221;
</p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.red-sweater.com/blog/825/getting-pretty-lonely/feed</wfw:commentRss>
		<slash:comments>128</slash:comments>
		</item>
		<item>
		<title>JSTalk &#8211; An Alternative To AppleScript?</title>
		<link>http://www.red-sweater.com/blog/775/jstalk-an-alternative-to-applescript</link>
		<comments>http://www.red-sweater.com/blog/775/jstalk-an-alternative-to-applescript#comments</comments>
		<pubDate>Fri, 27 Mar 2009 03:53:29 +0000</pubDate>
		<dc:creator>Daniel Jalkut</dc:creator>
				<category><![CDATA[AppleScript]]></category>
		<category><![CDATA[Business]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Links]]></category>

		<guid isPermaLink="false">http://www.red-sweater.com/blog/?p=775</guid>
		<description><![CDATA[My friend Gus Mueller of Flying Meat is having a busy week. On Tuesday it was revealed that his awesome image editing application, Acorn, is part of the MacHeist 3 Bundle. I have been openly critical of these rock-bottom-pricing bundles in the past, and I remain uncertain as to their long-term benefits for the Mac [...]]]></description>
			<content:encoded><![CDATA[<p>My friend Gus Mueller of <a href="http://flyingmeat.com/">Flying Meat</a> is having a busy week. On Tuesday it was revealed that his awesome image editing application, <a href="http://flyingmeat.com/acorn/">Acorn</a>, is part of the <a href="http://www.macheist.com/">MacHeist 3 Bundle</a>. I have been openly critical of these rock-bottom-pricing bundles in the past, and I remain uncertain as to their long-term benefits for the Mac software ecosystem. But in the short-term, consumers obviously have the option of picking up some amazing software for an unbeatable price. And if folks like Gus end up benefiting then I wish them the best.</p>
<p>
In the wake of his high profile MacHeist debut, Gus announced something new today which is decidedly less consumer-oriented (though if it takes off, it could certainly have wide-reaching consequences). <a href="http://gusmueller.com/blog/archives/2009/03/introducing_jstalk__an_alternative_to_applescript.html">JSTalk</a> is Gus&#8217;s JavaScript-based answer to what he sees as outdated and clunky about AppleScript, Apple&#8217;s preferred scripting language on the Mac.
</p>
<p>
For starters, Gus&#8217;s JSTalk provides syntactic sugar on top of standard JavaScript in order to give it some comfortable Objective-C style conveniences. Then, he provides a teeny bit of source code that any application can embed in order to respond to incoming JavaScript commands. This results in a scenario where an Objective-C based application can easily expose its internals to other applications, so that a script written in JSTalk can control it from another application.
</p>
<p>
I&#8217;m excited about the idea of JavaScript taking a more prominent role in the scripting infrastructure of Mac OS X. In fact, about 9 months ago I <a href="http://www.red-sweater.com/blog/502/apples-script">wrote some challenging words</a> about my opinion on the matter. Responding to Apple&#8217;s impressive enhancements to JavaScript in the context of WebKit:
</p>
<blockquote><p>
I hold a soft spot in my heart for AppleScript. But I’m slightly more of a pragmatist than a romantic. If JavaScript is what Apple cares most about, and JavaScript is where massive performance improvements are going to be made, then Apple should leverage those improvements to the benefit of every desktop scripter.
</p></blockquote>
<p>
Since then, Apple has given no indication of pursuing a system-wide infrastructure for JavaScript scripting. So in comes Gus Mueller with JSTalk, and solves the problem. Right? Well, sort of. Gus&#8217;s idea is very cool and clever given the constraints he&#8217;s working with. Namely, he can&#8217;t easily control how every application works, or how it interacts with the system and every other application. His solution is cool, and may even be worth adding support for to your application, but it&#8217;s not as cool as a system-wide, Apple-endorsed solution would be.
</p>
<p>
Michael Tsai makes <a href="http://mjtsai.com/blog/2009/03/26/introducing-jstalk/">some smart observations</a> about JSTalk, also agreeing that it&#8217;s cool, but taking exception to Gus&#8217;s claim that getting away from the rigid structure of AppleScript&#8217;s XML-based scripting dictionaries is a good thing:
</p>
<blockquote><p>
I think defining the object model, e.g. using XML, is a feature. Otherwise there’s no separation between the scripting interface and the application’s unstable internal interfaces.
</p></blockquote>
<p>
Taking a closer look at Michael&#8217;s post, I think I could have avoided this somewhat long-winded post by starting simply with, &#8220;Yeah, what Michael said.&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.red-sweater.com/blog/775/jstalk-an-alternative-to-applescript/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

