<?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>Jabbering Giraffe &#187; osx</title>
	<atom:link href="http://happygiraffe.net/blog/tag/osx/feed/" rel="self" type="application/rss+xml" />
	<link>http://happygiraffe.net/blog</link>
	<description></description>
	<lastBuildDate>Tue, 07 Feb 2012 20:49:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>Xcode Build Settings</title>
		<link>http://happygiraffe.net/blog/2010/04/30/xcode-build-settings/</link>
		<comments>http://happygiraffe.net/blog/2010/04/30/xcode-build-settings/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 15:25:55 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1670</guid>
		<description><![CDATA[One thing I keep coming up against in Xcode projects is that the build settings aren&#8217;t quite right. Why is ZERO_LINK enabled when target T2 is built with configuration C4? Unfortunately, you quickly end up with a very large combination &#8230; <a href="http://happygiraffe.net/blog/2010/04/30/xcode-build-settings/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One thing I keep coming up against in Xcode projects is that the build settings aren&#8217;t <em>quite</em> right.  Why is ZERO_LINK enabled when target <em>T2</em> is built with configuration <em>C4</em>?  Unfortunately, you quickly end up with a very large combination of options.  Six targets and four configurations means twenty four combinations to think about.  Which is madness.</p>
<p>There is an easier way: <a href="http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/XcodeBuildSystem/400-Build_Configurations/build_configs.html#//apple_ref/doc/uid/TP40002692-SW8">build settings files</a> (<code>*.xcconfig</code>).  These are text files with the same settings that are normally embedded into your xcodeproj file.  For example, on a newly created cocoa application, these are the settings that are present by default in the <em>Debug</em> configuration.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">ARCHS<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span>ARCHS_STANDARD_32_BIT<span style="color: #009900;">&#41;</span>
GCC_C_LANGUAGE_STANDARD<span style="color: #339933;">=</span>c99
GCC_OPTIMIZATION_LEVEL<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span>
GCC_WARN_ABOUT_RETURN_TYPE<span style="color: #339933;">=</span>YES
GCC_WARN_UNUSED_VARIABLE<span style="color: #339933;">=</span>YES
ONLY_ACTIVE_ARCH<span style="color: #339933;">=</span>YES
PREBINDING<span style="color: #339933;">=</span>NO
SDKROOT<span style="color: #339933;">=</span>macosx10.5</pre></div></div>

<p>And these are the ones in the <em>Release</em> configuration.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">ARCHS<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span>ARCHS_STANDARD_32_BIT<span style="color: #009900;">&#41;</span>
GCC_C_LANGUAGE_STANDARD<span style="color: #339933;">=</span>c99
GCC_WARN_ABOUT_RETURN_TYPE<span style="color: #339933;">=</span>YES
GCC_WARN_UNUSED_VARIABLE<span style="color: #339933;">=</span>YES
PREBINDING<span style="color: #339933;">=</span>NO
SDKROOT<span style="color: #339933;">=</span>macosx10.5</pre></div></div>

<p>Hmmm, they look quite similar (run diff(1) to see).  We can extract a common file (Choose File &rarr; New File… &rarr; Other &rarr; Configuration Setting File).</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Project-Common.xcconfig</span>
&nbsp;
ARCHS<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span>ARCHS_STANDARD_32_BIT<span style="color: #009900;">&#41;</span>
GCC_C_LANGUAGE_STANDARD<span style="color: #339933;">=</span>c99
GCC_WARN_ABOUT_RETURN_TYPE<span style="color: #339933;">=</span>YES
GCC_WARN_UNUSED_VARIABLE<span style="color: #339933;">=</span>YES
PREBINDING<span style="color: #339933;">=</span>NO
SDKROOT<span style="color: #339933;">=</span>macosx10.5
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// Project-Debug.xcconfig</span>
&nbsp;
<span style="color: #339933;">#include &quot;Project-Common.xcconfig&quot;</span>
&nbsp;
GCC_OPTIMIZATION_LEVEL<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span>
ONLY_ACTIVE_ARCH<span style="color: #339933;">=</span>YES
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// Project-Release.xcconfig</span>
&nbsp;
<span style="color: #339933;">#include &quot;Project-Common.xcconfig&quot;</span></pre></div></div>

<p>To apply these, go into the Build tab of the Project Info pane, and select the <em>Debug</em> configuration.  Delete all the settings in there (⌘-A, ⌫) and then select “Based On: Project-Debug”.  Do the same for the <em>Release</em> configuration, except base it on Project-Release.</p>
<div style="text-align:center;"><img src="http://happygiraffe.net/blog/wp-content/uploads/2010/04/Project-Debug.png" alt="Debug configuration settings" border="0" width="390" height="593" /></div>
<p>Now, you can add a setting to <code>Project-Common.xcconfig</code> and it will show up in all your configurations.  As a nice side effect, it&#8217;ll be much easier to see the change in version control.</p>
<p>What about targets?  Well, the same principle applies.  Except that you want to “push up” as much configuration as possible into your project level xcconfig files.</p>
<p>Let&#8217;s take a look at the default Debug configuration for my “Polynomials” target.</p>
<pre class="prettyprint">
INSTALL_PATH = $(HOME)/Applications
COPY_PHASE_STRIP = NO
INFOPLIST_FILE = Info.plist
PRODUCT_NAME = Polynomials
ALWAYS_SEARCH_USER_PATHS = NO
GCC_ENABLE_FIX_AND_CONTINUE = YES
GCC_DYNAMIC_NO_PIC = NO
GCC_MODEL_TUNING = G5
GCC_ENABLE_OBJC_GC = required
GCC_OPTIMIZATION_LEVEL = 0
GCC_PRECOMPILE_PREFIX_HEADER = YES
GCC_PREFIX_HEADER = Polynomials_Prefix.pch
</pre>
<p>The only really target specific settings are INFOPLIST_FILE and PRODUCT_NAME.  The rest can either be deleted (GCC_MODEL_TUNING?!?), or pushed up into the project level settings (GCC_OPTIMIZATION_LEVEL, which is already defined there).</p>
<p>It&#8217;s a really worthwhile exercise going through your project in order to clean up your build settings.  You&#8217;d be surprised at what&#8217;s going on in there.  Keep a copy of the Xcode <a href="http://developer.apple.com/mac/library/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/0-Introduction/introduction.html">Build Settings Reference</a> handy to look things up and see if you <em>really</em> need them.  If you want an example, I noticed that Eric Czarny&#8217;s lovely <a href="http://github.com/eczarny/xmlrpc">XMLRPC library</a> is organised somewhat like this.</p>
<p>You can do a lot more mad things with xcconfig&#8217;s, like choosing alternate signing personalities.  But extracting your current configuration is a good start.</p>
<p>In order to help the transition, I wrote a bit of applescript to pull out existing settings.  It&#8217;s pretty nasty because I don&#8217;t really get applescript.  But it Works For Me™.</p>

<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">set</span> newLine <span style="color: #ff0033; font-weight: bold;">to</span> ASCII character <span style="color: #000000;">10</span>
&nbsp;
<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Xcode&quot;</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> proj <span style="color: #ff0033; font-weight: bold;">to</span> project <span style="color: #000000;">1</span>
    <span style="color: #808080; font-style: italic;">-- This is a string of a POSIX path.</span>
    <span style="color: #ff0033; font-weight: bold;">set</span> dir <span style="color: #ff0033; font-weight: bold;">to</span> project directory <span style="color: #ff0033; font-weight: bold;">of</span> proj
&nbsp;
    <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> cf <span style="color: #ff0033; font-weight: bold;">in</span> build configurations <span style="color: #ff0033; font-weight: bold;">of</span> proj
        <span style="color: #ff0033; font-weight: bold;">set</span> str <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span>
        <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> stg <span style="color: #ff0033; font-weight: bold;">in</span> build settings <span style="color: #ff0033; font-weight: bold;">of</span> cf
            <span style="color: #ff0033; font-weight: bold;">set</span> str <span style="color: #ff0033; font-weight: bold;">to</span> str <span style="color: #000000;">&amp;</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> stg<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;=&quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #000000;">&#40;</span>value <span style="color: #ff0033; font-weight: bold;">of</span> stg<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&amp;</span> newLine
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">-- Write the results to a file</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> filename <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;Project-&quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> cf<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;.xcconfig&quot;</span>
        <span style="color: #ff0033; font-weight: bold;">set</span> fileno <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">open</span> for access <span style="color: #000000;">&#40;</span>dir <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;/&quot;</span> <span style="color: #000000;">&amp;</span> filename<span style="color: #000000;">&#41;</span> <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">POSIX file</span> <span style="color: #ff0033; font-weight: bold;">with</span> write permission
        write str <span style="color: #ff0033; font-weight: bold;">to</span> fileno
        <span style="color: #0066ff;">close</span> access fileno
&nbsp;
        <span style="color: #808080; font-style: italic;">-- Sort the file to make it easier to diff.</span>
        <span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;cd &quot;</span> <span style="color: #000000;">&amp;</span> dir <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &amp;&amp; sort &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> filename <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &gt;&quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> filename <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;.tmp &amp;&amp; mv &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> filename <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;.tmp &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> filename
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Now, iterate through each target.</span>
    <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> tgt <span style="color: #ff0033; font-weight: bold;">in</span> targets <span style="color: #ff0033; font-weight: bold;">of</span> proj
        <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> cf <span style="color: #ff0033; font-weight: bold;">in</span> build configurations <span style="color: #ff0033; font-weight: bold;">of</span> tgt
            <span style="color: #ff0033; font-weight: bold;">set</span> str <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;&quot;</span>
            <span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> stg <span style="color: #ff0033; font-weight: bold;">in</span> build settings <span style="color: #ff0033; font-weight: bold;">of</span> build configuration <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> cf<span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">of</span> tgt
                <span style="color: #ff0033; font-weight: bold;">set</span> str <span style="color: #ff0033; font-weight: bold;">to</span> str <span style="color: #000000;">&amp;</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> stg<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;=&quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #000000;">&#40;</span>value <span style="color: #ff0033; font-weight: bold;">of</span> stg<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&amp;</span> newLine
            <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
&nbsp;
            <span style="color: #808080; font-style: italic;">-- Write the results to a file</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> filename <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;Target-&quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> tgt<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;-&quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">of</span> cf<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;.xcconfig&quot;</span>
            <span style="color: #ff0033; font-weight: bold;">set</span> fileno <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">open</span> for access <span style="color: #000000;">&#40;</span>dir <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;/&quot;</span> <span style="color: #000000;">&amp;</span> filename<span style="color: #000000;">&#41;</span> <span style="color: #ff0033;">as</span> <span style="color: #0066ff;">POSIX file</span> <span style="color: #ff0033; font-weight: bold;">with</span> write permission
            write str <span style="color: #ff0033; font-weight: bold;">to</span> fileno
            <span style="color: #0066ff;">close</span> access fileno
&nbsp;
            <span style="color: #808080; font-style: italic;">-- Sort the file to make it easier to diff.</span>
            <span style="color: #0066ff;">do shell script</span> <span style="color: #009900;">&quot;cd &quot;</span> <span style="color: #000000;">&amp;</span> dir <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &amp;&amp; sort &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> filename <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; &gt;&quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> filename <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;.tmp &amp;&amp; mv &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> filename <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot;.tmp &quot;</span> <span style="color: #000000;">&amp;</span> <span style="color: #0066ff;">quoted form</span> <span style="color: #ff0033; font-weight: bold;">of</span> filename
        <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
    <span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span></pre></div></div>

<p>And yes — applescript doesn&#8217;t have a sort function builtin.  WTF?</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2010/04/30/xcode-build-settings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keychained</title>
		<link>http://happygiraffe.net/blog/2010/04/26/keychained/</link>
		<comments>http://happygiraffe.net/blog/2010/04/26/keychained/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 08:24:40 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1667</guid>
		<description><![CDATA[I&#8217;m working on an OSX interface to a web service right now. Of course, one of the requirements is for a username and password. Simple — just use keychain, right? Well, it might be simple, apart from the fact that &#8230; <a href="http://happygiraffe.net/blog/2010/04/26/keychained/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on an OSX interface to a web service right now.  Of course, one of the requirements is for a username and password.  Simple — just use keychain, right?</p>
<p>Well, it might be simple, apart from the fact that <a href="http://developer.apple.com/mac/library/documentation/Security/Conceptual/keychainServConcepts/01introduction/introduction.html">Keychain Services</a> has a hoary old API.  It&#8217;s C-based, and is like taking a step back in time to the early &#8217;90s.  After using the rest of the Cocoa Objective-C APIs, it&#8217;s a real shock.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">  <span style="color: #11740a; font-style: italic;">// Try to find a password.</span>
  <span style="color: #a61390;">const</span> <span style="color: #a61390;">char</span> <span style="color: #002200;">*</span>svc <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">&quot;ABCD&quot;</span>;
  SecKeychainItemRef itemRef <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
  OSStatus st <span style="color: #002200;">=</span> SecKeychainFindGenericPassword<span style="color: #002200;">&#40;</span><span style="color: #a61390;">NULL</span>, <span style="color: #a61390;">strlen</span><span style="color: #002200;">&#40;</span>svc<span style="color: #002200;">&#41;</span>, svc, <span style="color: #2400d9;">0</span>, <span style="color: #a61390;">NULL</span>,
                                            <span style="color: #a61390;">NULL</span>, <span style="color: #a61390;">NULL</span>, <span style="color: #002200;">&amp;</span>itemRef<span style="color: #002200;">&#41;</span>;
&nbsp;
  <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>st <span style="color: #002200;">==</span> noErr<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// use the keychain item</span>
  <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
    NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Ooops, got error status %d&quot;</span>, st<span style="color: #002200;">&#41;</span>;
  <span style="color: #002200;">&#125;</span></pre></div></div>

<p>Pulling items out of a keychain is even more long winded.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">  UInt32 length;
  <span style="color: #a61390;">char</span> <span style="color: #002200;">*</span>password;
  SecKeychainAttribute attributes<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">4</span><span style="color: #002200;">&#93;</span>;
  SecKeychainAttributeList list;
  <span style="color: #11740a; font-style: italic;">// list attributes we want to read.</span>
  attributes<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>.tag <span style="color: #002200;">=</span> kSecAccountItemAttr;
  attributes<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>.tag <span style="color: #002200;">=</span> kSecDescriptionItemAttr;
  attributes<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#93;</span>.tag <span style="color: #002200;">=</span> kSecLabelItemAttr;
  attributes<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">3</span><span style="color: #002200;">&#93;</span>.tag <span style="color: #002200;">=</span> kSecModDateItemAttr;
&nbsp;
  list.count <span style="color: #002200;">=</span> <span style="color: #2400d9;">4</span>;
  list.attr <span style="color: #002200;">=</span> attributes;
  <span style="color: #11740a; font-style: italic;">// Can pass NULL for password if not needed.</span>
  OSStatus status <span style="color: #002200;">=</span> SecKeychainItemCopyContent<span style="color: #002200;">&#40;</span>item, <span style="color: #a61390;">NULL</span>, <span style="color: #002200;">&amp;</span>list, <span style="color: #002200;">&amp;</span>length, <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span> <span style="color: #002200;">**</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&amp;</span>password<span style="color: #002200;">&#41;</span>;
&nbsp;
  <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>status <span style="color: #002200;">==</span> noErr<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// Use the now filled-in attributes.  NB: Password is NOT zero terminated, but &quot;length&quot; long.</span>
  <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">// Complain bitterly.</span>
  <span style="color: #002200;">&#125;</span>
  SecKeychainItemFreeContent<span style="color: #002200;">&#40;</span><span style="color: #002200;">&amp;</span>list, password<span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>So what to do?  Of course, it&#8217;d be great if there were a nice, OO wrapper.  I had a quick look and found <a href="http://extendmac.com/EMKeychain/">EMKeyChain</a> (on <a href="http://github.com/maccheck/EMKeychain/">github</a>).   Here&#8217;s a sample usage:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">  <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>password <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>EMGenericKeychain passwordForUsername<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;dom&quot;</span>
                                                      service<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MyService&quot;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>It&#8217;s a world of difference.  Sadly, EMKeychain doesn&#8217;t <em>quite</em> support the use case I want.  I don&#8217;t necessarily know the username in advance.  This leaves me with a few choices:</p>
<ol>
<li> Give up, and just use the vanilla Keychain API.  <em>Bleurgh.</em>
<li> Fix EMKeychain to support my use case.
<li> Use the preferences API to store the username, and then EMKeychain will work as expected.
</ol>
<p>I&#8217;m leaning quite strongly towards the third option.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2010/04/26/keychained/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The joy of apple keyboards</title>
		<link>http://happygiraffe.net/blog/2009/11/03/the-joy-of-apple-keyboards/</link>
		<comments>http://happygiraffe.net/blog/2009/11/03/the-joy-of-apple-keyboards/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 22:56:13 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[unicode]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1638</guid>
		<description><![CDATA[Recently, I&#8217;ve been using a Linux desktop for the first time in ages. It&#8217;s Ubuntu (Hardy Heron), and it looks nice. But after using a mac for three years, I&#8217;m really missing quite a few little things. The ability to &#8230; <a href="http://happygiraffe.net/blog/2009/11/03/the-joy-of-apple-keyboards/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently, I&#8217;ve been using a Linux desktop for the first time in ages.  It&#8217;s Ubuntu (Hardy Heron), and it looks nice.  But after using a mac for three years, I&#8217;m really missing quite a few little things.</p>
<ol>
<li>The ability to drag and drop anything anywhere.</li>
<li>Being able to type a wide range of Unicode characters easily.</li>
</ol>
<p>On a mac, it&#8217;s really, really easy to type in a wide variety of useful characters.  All you need is alt (&#x2325;), sometimes known as “option”.</p>
<table border="1">
<tr>
<th>Keys</th>
<th>Character</th>
<th>Name</th>
</tr>
<tr>
<td><code>&#x2325; ;</code></td>
<td>…</td>
<td>HORIZONTAL ELLIPSIS</td>
</tr>
<tr>
<td><code>&#x2325; -</code></td>
<td>–</td>
<td>EN DASH</td>
</tr>
<tr>
<td><code>&#x2325; &#x21E7; -</code></td>
<td>—</td>
<td>EM DASH</td>
</tr>
<tr>
<td><code>&#x2325; [</code></td>
<td>“</td>
<td>LEFT DOUBLE QUOTATION MARK</td>
</tr>
<tr>
<td><code>&#x2325; &#x21E7; [</code></td>
<td>”</td>
<td>RIGHT DOUBLE QUOTATION MARK</td>
</tr>
<tr>
<td><code>&#x2325; 2</code></td>
<td>™</td>
<td>TRADE MARK SIGN</td>
</tr>
<tr>
<td><code>&#x2325; 8</code></td>
<td>•</td>
<td>BULLET</td>
</tr>
<tr>
<td><code>&#x2325; e &nbsp; e</code></td>
<td>é</td>
<td> LATIN SMALL LETTER E WITH ACUTE </td>
</tr>
</table>
<p>How did I find all this out?  The lovely keyboard viewer that comes with OS X.  You can get the flag in your menu bar by going to International in system preferences and checking “Show input menu in menu bar.”</p>
<div style="text-align:center;"><img src="http://happygiraffe.net/blog/wp-content/uploads/2009/11/input-menu.png" alt="Selecting the keyboard viewer in the input menu" border="0" width="237" height="196" /></div>
<div style="text-align:center;"><img src="http://happygiraffe.net/blog/wp-content/uploads/2009/11/keyboard-viewer-normal.png" alt="OS X Keyboard Viewer (normal state)" border="0" width="318" height="175" /></div>
<p>Now, hold down alt and see what you can get (try alt and shift too).</p>
<div style="text-align:center;"><img src="http://happygiraffe.net/blog/wp-content/uploads/2009/11/image-capture-alt.png" alt="OS X Keyboard Viewer (alt)" border="0" width="318" height="175" /></div>
<p>But not everything is attached to a key.  In case you need more characters, there&#8217;s always the character palette.  Usually on the <code>&#x2325; &#x2318; T</code> key as well as in the Edit menu.  Here, you can get access to the vast repertoire of characters in Unicode.  Need an arrow?</p>
<div style="text-align:center;"><img src="http://happygiraffe.net/blog/wp-content/uploads/2009/11/character-palette-arrows.png" alt="Arrows in the Character Palette" border="0" width="370" height="390" /></div>
<p>There&#8217;s a lot you can do with the character palette, but the search box is probably the best way in.  Just tap in a bit of the name of the character you&#8217;re looking for and see what turns up.</p>
<p>This easy access to a wide array of characters is something I&#8217;ve rather come to take for granted in OS X.  So coming back to the Linux desktop, it was odd to find that I couldn&#8217;t as readily type them in.  Of course, I haven&#8217;t invested the time in figuring out how to set up <a href="http://en.wikipedia.org/wiki/X_keyboard_extension">XKB</a> correctly.  Doubtless I could achieve many of the same things.  But my past experiences of XKB and it&#8217;s documentation have shown me how complicated it can be, so I don&#8217;t rate my ability to pull it off.</p>
<p>The end result is that I&#8217;m spending most of my time on the (mac) laptop and ignoring the desktop.  I do like my characters. <img src='http://happygiraffe.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/11/03/the-joy-of-apple-keyboards/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ASL (Apple System Log)</title>
		<link>http://happygiraffe.net/blog/2009/10/20/asl-apple-system-log/</link>
		<comments>http://happygiraffe.net/blog/2009/10/20/asl-apple-system-log/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 19:42:58 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1632</guid>
		<description><![CDATA[I&#8217;ve just been debugging a problem with the pulse-agent on a mac. One of the big questions we had was: where the heck are the logs? The pulse-agent is managed by launchd. Apparently, this logs all stdout and stderr via &#8230; <a href="http://happygiraffe.net/blog/2009/10/20/asl-apple-system-log/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just been debugging a problem with the pulse-agent on a mac.  One of the big questions we had was: where the heck are the logs?  The pulse-agent is managed by <a href="http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man8/launchd.8.html#//apple_ref/doc/man/8/launchd">launchd</a>.  Apparently, this <a href="http://developer.apple.com/mac/library/technotes/tn2005/tn2083.html#SECLOGGING">logs all stdout and stderr via ASL</a>.</p>
<p>But what&#8217;s ASL?  Apparently, it&#8217;s the Apple System Log.  There&#8217;s a nice summary on <a href="http://boredzo.org/blog/archives/2008-01-19/next-week-apple-system-logger">Domain of the Bored</a>.  He also gives the key hint: you can use <a href="http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/syslog.1.html">syslog(1)</a> to read the binary ASL files.</p>
<p>I didn&#8217;t delve too deeply into the flags.  It appeared that just running <code>syslog</code> spat out all the information I required.  But, it comes out encoded like <code>cat -v</code>.  But you can pipe it through <a href="http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/unvis.1.html">unvis(1)</a> to clean that up.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ syslog <span style="color: #000000; font-weight: bold;">|</span> unvis <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">less</span></pre></div></div>

<p>Normally, <code>Console.app</code> would take care of all this transparently.  But when you&#8217;re ssh&#8217;d into a mac, that&#8217;s not an option.  So it&#8217;s good to know about syslog(1).</p>
<p>Looking closer at the flags, you can say <code>syslog -E safe</code> in place of piping through unvis(1).</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/10/20/asl-apple-system-log/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript.pm on OSX</title>
		<link>http://happygiraffe.net/blog/2009/08/24/javascript-pm-on-osx/</link>
		<comments>http://happygiraffe.net/blog/2009/08/24/javascript-pm-on-osx/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 23:02:29 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1594</guid>
		<description><![CDATA[Just a quick note… I was looking at RT#48699 when I noticed that MacPorts didn&#8217;t have JavaScript.pm in it&#8217;s collection. I needed to install it by hand. Unfortunately, the latest version (1.12) doesn&#8217;t install cleanly. So I&#8217;ve forked it and &#8230; <a href="http://happygiraffe.net/blog/2009/08/24/javascript-pm-on-osx/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Just a quick note…  I was looking at <a href="http://rt.cpan.org/Ticket/Display.html?id=48699">RT#48699</a> when I noticed that <a href="http://www.macports.org/">MacPorts</a> didn&#8217;t have <a href="http://search.cpan.org/perldoc?JavaScript">JavaScript.pm</a> in it&#8217;s collection.  I needed to install it by hand.  Unfortunately, the latest version (1.12) doesn&#8217;t install cleanly.</p>
<p>So I&#8217;ve <a href="http://github.com/happygiraffe/javascript">forked it</a> and <a href="http://github.com/happygiraffe/javascript/commit/e45e5307286697b27a88027d4f1f66e7e6d64c7f">fixed it</a> (along with a couple of other minor nits).</p>
<p>Claes <a href="http://twitter.com/claesjac/status/3305316805">said</a> he&#8217;ll apply the patch at some point.  So hopefully when 1.13 comes out, this won&#8217;t be necessary.</p>
<p>Of course, really I should get to grips with MacPorts and submit a <a href="http://guide.macports.org/#development">Portfile</a>…</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/08/24/javascript-pm-on-osx/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using a Java 6 based Eclipse with Cocoa</title>
		<link>http://happygiraffe.net/blog/2009/07/15/using-a-java-6-based-eclipse-with-cocoa/</link>
		<comments>http://happygiraffe.net/blog/2009/07/15/using-a-java-6-based-eclipse-with-cocoa/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 19:37:57 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1553</guid>
		<description><![CDATA[This is somewhat niche, but I&#8217;m going to post it anyway in case it helps somebody else… I recently saw a problem with Eclipse and m2eclipse. When I tried to import a Java 6 based project, I got an error &#8230; <a href="http://happygiraffe.net/blog/2009/07/15/using-a-java-6-based-eclipse-with-cocoa/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is somewhat niche, but I&#8217;m going to post it anyway in case it helps <a href="http://archive.m2eclipse.codehaus.org/lists/org.codehaus.m2eclipse.user/msg/24497016.post@talk.nabble.com">somebody else</a>…</p>
<p>I recently saw a problem with Eclipse and <a href="http://m2eclipse.codehaus.org/">m2eclipse</a>.  When I tried to import a Java 6 based project, I got an error in the maven console.</p>
<pre>
Failure executing javac, but could not parse the error:
javac: invalid target release: 1.6
Usage: javac
<options> <source files>
where possible options include:
 -g                         Generate all debugging info
 -g:none                    Generate no debugging info
 -g:{lines,vars,source}     Generate only some debugging info
 -nowarn                    Generate no warnings
 -verbose                   Output messages about what the compiler is doing
</pre>
<p>This is happening because m2eclipse is trying to run the compiler from within the same JVM that Eclipse is running.  And by the <a href="http://www.eclipse.org/downloads/">eclipse.org downloads</a> only offer Carbon and Cocoa options.  Both of these are 32 bit.  Which means they&#8217;ll only ever run using Java 5, even if you&#8217;ve got Java 6 installed (unlike my iMac G5, <em>grumble, grumble</em>).</p>
<p>Thankfully, the 64 cocoa version is available, though it&#8217;s only the old &#8220;Eclipse SDK&#8221; download.  But <a href="http://ekkescorner.wordpress.com/">ekke</a> wrote up <a href="http://ekkescorner.wordpress.com/2009/06/30/galileo-epp-for-cocoa-64-bit/">[galileo] EPP for Cocoa 64-bit</a>, which shows how to go about getting (effectively) the same setup as the eclipse.org downloads.</p>
<p>If you follow along that procedure, you get an eclipse that works well with m2eclipse and Java 6 project.  As a bonus, it feels quicker to me.</p>
<p>Hopefully future versions of Eclipse will offer a 64-bit cocoa download.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/07/15/using-a-java-6-based-eclipse-with-cocoa/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Eclipse 3.5 in Cocoa</title>
		<link>http://happygiraffe.net/blog/2009/06/10/eclipse-3-5-in-cocoa/</link>
		<comments>http://happygiraffe.net/blog/2009/06/10/eclipse-3-5-in-cocoa/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 12:39:04 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1535</guid>
		<description><![CDATA[I&#8217;m just trying out Eclipse 3.5-RC4. One of the big new features for me is that it&#8217;s now based on Cocoa instead of Carbon. There are many benefits to this, including being able to run on 64-bit Java 6. Fundamentally, &#8230; <a href="http://happygiraffe.net/blog/2009/06/10/eclipse-3-5-in-cocoa/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m just trying out <a href="http://download.eclipse.org/eclipse/downloads/drops/S-3.5RC4-200906051444/index.php">Eclipse 3.5-RC4</a>.  One of the big new features for me is that it&#8217;s now based on <a href="http://developer.apple.com/cocoa/">Cocoa</a> instead of <a href="http://developer.apple.com/carbon/">Carbon</a>.  There are many benefits to this, including being able to run on 64-bit Java 6.  Fundamentally, it just looks and feels a little bit more mac-like.</p>
<p>As an example, one nice little mac feature I use a bit is &#8220;lookup this word in the dictionary&#8221;.  If you hit <code>Ctrl-Cmd-D</code> and hover over a word, you get an in-place definition.  Eclipse now does this:</p>
<div style="text-align:center;"><img src="http://happygiraffe.net/blog/wp-content/uploads/2009/06/eclipse-dict-lookup.png" alt="Looking up a word in the dictionary inside Eclipse" border="0" width="314" height="275" /></div>
<p>It doesn&#8217;t work everywhere (which you can probably guess from the context of that screenshot), but it is an indicator that Eclipse &#038; mac are coming together.  This is great news for Java developers on the mac.</p>
<p>Oh, it does feel a little bit faster too, which can&#8217;t hurt.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/06/10/eclipse-3-5-in-cocoa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sandbox(7)</title>
		<link>http://happygiraffe.net/blog/2009/06/02/sandbox7/</link>
		<comments>http://happygiraffe.net/blog/2009/06/02/sandbox7/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 20:12:06 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1524</guid>
		<description><![CDATA[Like a lot of people, most of my Unix knowledge comes from an early reading of Advanced Programming in the UNIX Environment. This is an excellent tome on the interfaces provided by the kernel to programs on a Unix system. &#8230; <a href="http://happygiraffe.net/blog/2009/06/02/sandbox7/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Like a lot of people, most of my Unix knowledge comes from an early reading of <a href="http://www.kohala.com/start/apue.html">Advanced Programming in the UNIX Environment</a>.  This is an <em>excellent</em> tome on the interfaces provided by the kernel to programs on a Unix system.</p>
<p>Unfortunately, it&#8217;s over 15 years old now, and things have moved on.  Naturally, I haven&#8217;t quite kept up.  So I&#8217;ve just been pleasantly surprised to see that OS X has grown a sandbox system (<a href="http://blog.chromium.org/2009/06/google-chrome-sandboxing-and-mac-os-x.html">via</a>).  There is scant documentation available:</p>
<ul>
<li><a href="http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man1/sandbox-exec.1.html#//apple_ref/doc/man/1/sandbox-exec">sandbox-exec(1)</a></li>
<li><a href="http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man3/sandbox_init.3.html">sandbox_init(3)</a></li>
<li><a href="http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man7/sandbox.7.html#//apple_ref/doc/man/7/sandbox">sandbox(7)</a></li>
<li><a href="http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man8/sandbox-compilerd.8.html#//apple_ref/doc/man/8/sandbox-compilerd">sandbox-compilerd(8)</a></li>
</ul>
<p>Also, if you poke around, you&#8217;ll find <code>/usr/include/sandbox.h</code> and <code>/usr/share/sandbox</code>.  The latter is interesting — it contains lisp-like definitions of access control lists for various processes.</p>
<p>What&#8217;s interesting to me is <code>sandbox-exec</code> though.  This can be used with one of the builtin profiles to easily restrict access.  For example:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ sandbox-exec <span style="color: #660033;">-n</span> nowrite <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>foo
<span style="color: #c20cb9; font-weight: bold;">touch</span>: <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>foo: Operation not permitted</pre></div></div>

<p>After using <a href="http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man1/strings.1.html">strings(1)</a> on apple&#8217;s libc (<code>/usr/lib/libSystem.dylib</code>), I managed to get these builtin profile names out:</p>
<dl>
<dt><em>nointernet</em></dt>
<dd>TCP/IP networking is prohibited</dd>
<dt><em>nonet</em></dt>
<dd>All sockets-based networking is prohibited.</dd>
<dt><em>pure-computation</em></dt>
<dd>All operating system services are prohibited.</dd>
<dt><em>nowrite</em></dt>
<dd>File system writes are prohibited.</dd>
<dt><em>write-tmp-only</em></dt>
<dd>File system writes are restricted to the temporary folder <code>/var/tmp</code> and the folder specified by the <a href="http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man3/confstr.3.html#//apple_ref/doc/man/3/confstr">confstr(3)</a> configuration variable <code>_CS_DARWIN_USER_TEMP_DIR</code>.</dd>
</dl>
<p>They&#8217;re only documented as internal constants for C programs, but it&#8217;s quite handy to have them available for <code>sandbox-exec</code>.  It would be nice to know in more detail what they actually <em>did</em>, though.</p>
<p>Of course, this still isn&#8217;t really getting down to how the sandbox is implemented.  Is it done inside the kernel or on the userland side?  I don&#8217;t really know.  And I don&#8217;t yet have enough dtrace-fu to figure it out.</p>
<p>See also:</p>
<ul>
<li><a href="http://www.318.com/techjournal/security/a-brief-introduction-to-mac-os-x-sandbox-technology/">A brief introduction to Mac OS X SandBox Technology</a></li>
<li><a href="http://www.usefulsecurity.com/2007/11/apple-sandboxes-part-1/">Apple Sandboxes Part 1</a></li>
<li><a href="http://www.usefulsecurity.com/2007/11/apple-sandboxes-part-2/">Apple Sandboxes Part 2</a></li>
<li><a href="http://www.matasano.com/log/981/a-roundup-of-leopard-security-features/">A Roundup Of Leopard Security Features</a></li>
</ul>
<p>Anyway, this seems like a fun toy.  And of course, it&#8217;s reminded me that I need to try out <a href="http://build.chromium.org/buildbot/snapshots/sub-rel-mac/">chromium on the mac</a>…  Drat, no PPC support.  <img src='http://happygiraffe.net/blog/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/06/02/sandbox7/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Removing CAPS LOCK on OS X</title>
		<link>http://happygiraffe.net/blog/2008/11/24/removing-caps-lock-on-os-x/</link>
		<comments>http://happygiraffe.net/blog/2008/11/24/removing-caps-lock-on-os-x/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 10:52:25 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1421</guid>
		<description><![CDATA[This has been bugging me for a while, but I&#8217;ve just gotten around to doing anything about it. I hate the caps lock key. I never use it and I&#8217;m always triggering it by accident. Thankfully, it&#8217;s fairly simple to &#8230; <a href="http://happygiraffe.net/blog/2008/11/24/removing-caps-lock-on-os-x/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This has been bugging me for a while, but I&#8217;ve just gotten around to doing anything about it.  I hate the caps lock key.  I never use it and I&#8217;m always triggering it by accident.  Thankfully, it&#8217;s fairly simple to disable.  First go into System Preferences and choose &#8220;Keyboard &#038; Mouse&#8221;.</p>
<div style="text-align:center;"><img src="http://happygiraffe.net/blog/wp-content/uploads/2008/11/syspref-keyboard-and-mouse.png" alt="System Preferences: Keyboard &#038; Mouse" border="0" width="96" height="90" /></div>
<p>Now on the &#8220;Keyboard&#8221; tab, there&#8217;s a button in the bottom left that I&#8217;d managed to miss entirely, &#8220;modifier keys&#8221;:</p>
<div style="text-align:center;"><img src="http://happygiraffe.net/blog/wp-content/uploads/2008/11/syspref-keyboard-button.png" alt="System Preferences: Keyboard" border="0" width="207" height="80" /></div>
<p>This pops up a little dialog pane that lets you choose the behaviour of the caps lock key.</p>
<div style="text-align:center;"><img src="http://happygiraffe.net/blog/wp-content/uploads/2008/11/syspref-modifier-keys.png" alt="System Preferences: Modifier Keys" border="0" width="417" height="279" /></div>
<p>I chose control, as it&#8217;s not entirely useless.  In fact, on my macbook, it&#8217;s a damned sight more useful than the hobbled control key which has been displaced by an &#8220;Fn&#8221; button.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2008/11/24/removing-caps-lock-on-os-x/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Expanding Outline Views in Cocoa</title>
		<link>http://happygiraffe.net/blog/2008/03/30/expanding-outline-views-in-cocoa/</link>
		<comments>http://happygiraffe.net/blog/2008/03/30/expanding-outline-views-in-cocoa/#comments</comments>
		<pubDate>Sun, 30 Mar 2008 21:42:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2008/03/30/expanding-outline-views-in-cocoa/</guid>
		<description><![CDATA[Thanks to a lengthy commute last week, I&#8217;ve been making a toy in Cocoa. It reads an URL, parses some XML and displays it in an NSOutlineView. Simple stuff, but it will hopefully make my life better at work, where &#8230; <a href="http://happygiraffe.net/blog/2008/03/30/expanding-outline-views-in-cocoa/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Thanks to a lengthy commute last week, I&#8217;ve been making a toy in Cocoa.  It reads an <span class="caps">URL</span>, parses some <span class="caps">XML</span> and displays it in an <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSOutlineView_Class/Reference/Reference.html">NSOutlineView</a>.  Simple stuff, but it will hopefully make my life better at work, where I need to do this a fair bit.</p>
<p>By default, when I load the <span class="caps">XML</span> into the NSOutlineView, everything is closed up.  So all you&#8217;re presented with is the root element.  I&#8217;d like to expand that so it automatically includes all children of the root element.  Nice and simple&#8212;there&#8217;s an <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSOutlineView_Class/Reference/Reference.html#//apple_ref/occ/instm/NSOutlineView/expandItem">expandItem</a>: method.</p>
<p>Except that when I call it from the action that puts the <span class="caps">XML</span> into the NSOutlineView, it doesn&#8217;t work.  Bugger.</p>
<p>After instrumenting my <span class="caps">XML</span> data source, I can see that nothing is really happening until <em>after</em> my action.  My suspicion is that the NSOutlineView isn&#8217;t realising that it has any data until after the first call to <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSView_Class/Reference/NSView.html#//apple_ref/occ/instm/NSView/display">display</a>.</p>
<p>I tested this by hooking up the call to expandItem into a secondary action (on another button).  And it works great.</p>
<p>So, I need a way to say &#8220;call this code back in the next idle period&#8221;.  And this is where I start to get upset that Objective-C doesn&#8217;t have closures.</p>
<p>How to execute code soon isn&#8217;t easily determined from the apple docs.  My guess is that you use an <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html">NSTimer</a> with a very small <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html#//apple_ref/doc/c_ref/NSTimeInterval">NSTimeInterval</a> .  Let&#8217;s try that&#8230;</p>
<pre>
  NSTimer *idle = [NSTimer scheduledTimerWithTimeInterval:0.0
                                                   target:self
                                                 selector:@selector(expandRoot)
                                                 userInfo:nil
                                                  repeats:NO];
  [[NSRunLoop currentRunLoop] addTimer:idle forMode:NSDefaultRunLoopMode];
</pre>
<p>Well, it works.  But! Further investigation finally reveals <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaPerformance/Articles/UnblockUI.html#//apple_ref/doc/uid/TP40001442-112061-BCIIEFBH">Deferring the Execution of Operations</a>.  This suggests that I should use an <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNotification_Class/Reference/Reference.html">NSNotification</a> instead, but posted with a <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNotificationQueue_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSPostWhenIdle">NSPostWhenIdle</a> flag.  This means getting involved with the <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/Notifications/Introduction/introNotifications.html">cocoa notifications system</a>&#8230;</p>
<p>The code now ends up looking like this:</p>
<pre>
  - (void)awakeFromNib
  {
    // Listen out for notification's we've posted to ourselves.
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(expandRoot:)
                                                 name:@"expandRoot"
                                               object:nil];
  }

  -(IBAction)fetch: (id)sender
  {
    // …
    NSNotification* todo = [NSNotification notificationWithName:@"expandRoot"
                                                         object:self];
    [[NSNotificationQueue defaultQueue] enqueueNotification:todo
                                               postingStyle:NSPostWhenIdle];
  }

  - (void)expandRoot:(NSNotification *)notification
  {
    [outlineView expandItem:[[outlineViewDataSource doc] rootElement]];
  }
</pre>
<p>Which is quite a bit more code.  But it feels more robust doing it this way.</p>
<p>The big take away from all this is how difficult it is to use a non-Open-Source framework.  If I had the source to Cocoa, I&#8217;d be able to look inside and see what I needed to do simply and quickly.  Instead, it took me three train journeys.  But there&#8217;s still enough to like in Cocoa that I intend to carry on.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2008/03/30/expanding-outline-views-in-cocoa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

