<?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/"
	xmlns:cc="http://creativecommons.org/ns#" >

<channel>
	<title>Shiny Pebbles... &#187; Xcode</title>
	<atom:link href="http://richard.milewski.org/archives/tag/xcode/feed" rel="self" type="application/rss+xml" />
	<link>http://richard.milewski.org</link>
	<description>A Compendium of Distractions</description>
	<lastBuildDate>Sat, 17 Dec 2011 17:47:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<cc:license >Attribution-ShareAlike CC BY-SA</cc:license><dc:rights  >Attribution-ShareAlike CC BY-SA</dc:rights>		<item>
		<title>A Recipe to Pretty-Print Your iPhone Source in Xcode</title>
		<link>http://richard.milewski.org/archives/224</link>
		<comments>http://richard.milewski.org/archives/224#comments</comments>
		<pubDate>Tue, 14 Jul 2009 15:41:27 +0000</pubDate>
		<dc:creator>ram</dc:creator>
				<category><![CDATA[Dev Tools]]></category>
		<category><![CDATA[Xcode]]></category>
		<category><![CDATA[Zemanta]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://richard.milewski.org/?p=224</guid>
		<description><![CDATA[<p>Apple&#8217;s Xcode development environment is the de-facto standard for creating iPhone apps. It&#8217;s fairly easy to use but suffers from having almost no print formatting capability. You&#8217;re stuck with all-black prints in big elementary-school sized type with no line numbers. Hardly a format that lends itself to easy reading. &#8230;and a few minutes on Google [...]]]></description>
			<content:encoded><![CDATA[<p>Apple&#8217;s Xcode development environment is the de-facto standard for creating iPhone apps.   It&#8217;s fairly easy to use but suffers from having almost no print formatting capability. You&#8217;re stuck with all-black prints in big elementary-school sized type with no line numbers.   Hardly a format that lends itself to easy reading.  &#8230;and a few minutes on Google didn&#8217;t turn up much in the way of work-arounds.   I did find and article that mentioned installing an old printing utility called enscript, but the only instructions I could find on the web were clearly aimed at an earlier version of Xcode.  However, a bit of fiddling and pawing through the enscript man pages yielded a fairly serviceable solution.</p>
<p>Here&#8217;s a recipe that will get you from ugly Xcode style printing to two-column, color, landscape formatted listings in 10 minutes flat.<span id="more-224"></span></p>
<p><strong>Update:</strong> I&#8217;ve had some reports that enscript is now installed by Apple on some systems.  If you&#8217;re running Snow Leopard (10.6.x) check to see if enscript is located at: /usr/bin/enscript.  If so you can skip the MacPorts install and go straight to the Xcode steps below.</p>
<p>If you don&#8217;t have MacPorts installed on your machine install it now.  There are easy instructions on the <a href="http://www.macports.org/">MacPorts Project Homepage</a>.</p>
<p>Then open a terminal window and type: <code>port install enscript</code></p>
<p>That will install the enscript shell script for pretty printing.  Next, open Xcode and click on the script menu, that&#8217;s the black scroll character between the Window and Help menus.  Select &#8220;Edit User Scripts&#8221;.</p>
<p>In the left-hand column named &#8220;Menu and Item Titles&#8221;, select the line labeled &#8220;Text&#8221;.</p>
<p>Click on the plus sign in the lower left corner and choose &#8220;New Shell Script&#8221; from the drop-down menu.  Double-click on the new &#8220;Shell Script&#8221; line that appears and change the name to &#8220;Pretty Print,&#8221; or a name of your choosing.</p>
<p>In the text box on the right you&#8217;ll have the &#8220;shebang&#8221; line for your new script:<br />
<code><br />
<blockquote>#! /bin/sh</p></blockquote>
<p></code></p>
<p>Edit the text so it looks like this:<br />
<code><br />
<blockquote>
#! /bin/sh<br />
#<br />
# enscript.sh - Print the file using enscript.<br />
#<br />
enscript -Eobjc -G -C -r --color -2 -T 4  "%%%{PBXFilePath}%%%"
</p></blockquote>
<p></code></p>
<p>Click on the arrows to drop down the list in the Output: field below the text window and select Output: Display in Alert.</p>
<p>That&#8217;s all there is to it!   Close the Edit User Scripts dialog, and you&#8217;re ready to print.   Open an Xcode project and double click on a source file to open it in a window of it&#8217;s own.  Then pick Pretty Print from the script menu and a neatly formatted source listing with line numbers and color highlighting will fall out of your printer.  </p>
<p>Enscript has a full bushel of command-line switches, so you can customize your output in many ways I haven&#8217;t mentioned here.  See the <a href="http://www.codento.com/people/mtr/genscript/enscript.man.html">enscript man page</a>for details.</p>
<p>The solution isn&#8217;t quite perfect, there are two shortcomings that I&#8217;ve identified so far;  First, the color highlighting doesn&#8217;t match the on-screen highlighting done by Xcode.  Someone with better REGEX skills than mine could probably fix that in an hour or so by editing the objc.st file that enscript installs in /usr/share/enscript/hl/.</p>
<p>The second problem is that the MacPorts version of enscript doesn&#8217;t seem to get the character encoding quite right.  I&#8217;ve noticed a few character set problems in my source file printouts, mostly dealing with degree symbols and such.  There&#8217;s a switch for something called &#8220;mac&#8221; encoding, but it doesn&#8217;t work at all with Xcode on MacOS X.</p>
<p>If you have a work-around for the character-set problem, or a new objc.st file you&#8217;d like to share, leave a comment and I&#8217;ll update this post.</p>
<div class="tweetthis" style="text-align:right;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=A+Recipe+to+Pretty-Print+Your+iPhone+Source+in+Xcode%2C+http%3A%2F%2Frichard.milewski.org%2F%3Fp%3D224" title="Post to Twitter"><img class="nothumb" src="http://richard.milewski.org/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-micro1.png" alt="Post to Twitter" /></a> <a class="tt" href="http://buzz.yahoo.com/buzz?targetUrl=http://richard.milewski.org/archives/224&amp;headline=A+Recipe+to+Pretty-Print+Your+iPhone+Source+in+Xcode" title="Post to Yahoo Buzz"><img class="nothumb" src="http://richard.milewski.org/blog/wp-content/plugins/tweet-this/icons/en/buzz/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a class="tt" href="http://delicious.com/post?url=http://richard.milewski.org/archives/224&amp;title=A+Recipe+to+Pretty-Print+Your+iPhone+Source+in+Xcode" title="Post to Delicious"><img class="nothumb" src="http://richard.milewski.org/blog/wp-content/plugins/tweet-this/icons/en/delicious/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://digg.com/submit?url=http://richard.milewski.org/archives/224&amp;title=A+Recipe+to+Pretty-Print+Your+iPhone+Source+in+Xcode" title="Post to Digg"><img class="nothumb" src="http://richard.milewski.org/blog/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://richard.milewski.org/archives/224&amp;t=A+Recipe+to+Pretty-Print+Your+iPhone+Source+in+Xcode" title="Post to Facebook"><img class="nothumb" src="http://richard.milewski.org/blog/wp-content/plugins/tweet-this/icons/en/facebook/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://www.myspace.com/Modules/PostTo/Pages/?l=3&amp;u=http://richard.milewski.org/archives/224&amp;t=A+Recipe+to+Pretty-Print+Your+iPhone+Source+in+Xcode" title="Post to MySpace"><img class="nothumb" src="http://richard.milewski.org/blog/wp-content/plugins/tweet-this/icons/en/myspace/tt-myspace.png" alt="Post to MySpace" /></a> <a class="tt" href="http://ping.fm/ref/?method=microblog&amp;title=A+Recipe+to+Pretty-Print+Your+iPhone+Source+in+Xcode&amp;link=http://richard.milewski.org/archives/224" title="Post to Ping.fm"><img class="nothumb" src="http://richard.milewski.org/blog/wp-content/plugins/tweet-this/icons/en/ping/tt-ping.png" alt="Post to Ping.fm" /></a> <a class="tt" href="http://reddit.com/submit?url=http://richard.milewski.org/archives/224&amp;title=A+Recipe+to+Pretty-Print+Your+iPhone+Source+in+Xcode" title="Post to Reddit"><img class="nothumb" src="http://richard.milewski.org/blog/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://richard.milewski.org/archives/224&amp;title=A+Recipe+to+Pretty-Print+Your+iPhone+Source+in+Xcode" title="Post to StumbleUpon"><img class="nothumb" src="http://richard.milewski.org/blog/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://richard.milewski.org/archives/224/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

