<?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>Kent Sutherland</title>
	<atom:link href="http://ksuther.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ksuther.com</link>
	<description>Mac and iOS development and possibly other miscellaneous things</description>
	<lastBuildDate>Sat, 16 Mar 2013 15:40:26 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Automating iOS App Store screenshots</title>
		<link>http://ksuther.com/2013/02/24/automating-ios-app-store-screenshots/</link>
		<comments>http://ksuther.com/2013/02/24/automating-ios-app-store-screenshots/#comments</comments>
		<pubDate>Sun, 24 Feb 2013 18:52:22 +0000</pubDate>
		<dc:creator>Kent Sutherland</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://ksuther.com/?p=288</guid>
		<description><![CDATA[This originated from a short talk about screenshot automation that I gave at the Boston CocoaHeads in January. My initial goal of the talk was to just show that it was possible to do such a thing and encourage others to consider automating their own processes, but there was some interest in a more detailed [...]]]></description>
				<content:encoded><![CDATA[<p>This originated from a short talk about screenshot automation that I gave at the <a href="http://www.cocoaheads.org/us/BostonMassachusetts/index.html">Boston CocoaHeads</a> in January. My initial goal of the talk was to just show that it was possible to do such a thing and encourage others to consider automating their own processes, but there was some interest in a more detailed write-up. Here it is. Also, thanks to Daniel Jalkut for his <a href="http://bitsplitting.org/2013/01/11/screenshot-lightning/">blog post</a> that stirred up some more interest.</p>
<h3>What does this look like?</h3>
<p>First off, what am I talking about? Here&#8217;s a video of Fantastical&#8217;s screenshot automation, which shows the complete process in action.</p>
<p><iframe width="560" height="315" src="http://www.youtube.com/embed/RUgUcvx0Ugg?rel=0" frameborder="0" allowfullscreen></iframe></p>
<h3>Why do I want to do this?</h3>
<p>Because you&#8217;re lazy. Why take screenshots manually when your computer can do it for you? For one, consider the math. Let&#8217;s say you have 5 screenshots for the App Store, for 5 languages. Oh yeah, you also have a 3.5 inch and a 4 inch screen. Maybe an iPad too. That&#8217;s 5 x 5 x 2 (or 3) screenshots to take. At 30 seconds a screenshot, that&#8217;s 25 (or 37.5) minutes just to take the screenshots. Don&#8217;t make any mistakes, otherwise it&#8217;ll take even longer. This probably isn&#8217;t a one time deal either, unless you never plan on changing your app again. Trust me, this is worth taking a couple of hours to add to your app. As you&#8217;ll see, I&#8217;ve even done some of the work for you.</p>
<h3>OK, show me an example</h3>
<p>First, grab the source from <a href="https://github.com/ksuther/KSScreenshotManager">KSScreenshotManager at GitHub</a>. Be sure you clone the WaxSim submodule, otherwise the included script won&#8217;t work. For those of you who aren&#8217;t familiar with submodules, the command you&#8217;re looking for is <code>git submodule update --init</code>. If you want to include this in your own project, add KSScreenshotManager as a submodule and add <code>KSScreenshotManager</code> and <code>KSScreenshotAction</code> to your project.</p>
<h3>Safety first</h3>
<p>Be aware that we&#8217;ll be using private API to get the job done. This doesn&#8217;t matter since this code isn&#8217;t going to the App Store, but take care that you don&#8217;t let private API declarations or usage slip into your shipping builds. You&#8217;ll notice that the example uses the macro <code>CREATING_SCREENSHOTS</code> to ensure that none of the screenshot code is included in normal builds.</p>
<h3>Defining your screenshots</h3>
<p>Digging into the sample code, <code>KSScreenshotManager</code> and the <code>MyScreenshotManager</code> subclass are what we&#8217;re interested in. This is where we specify what we actually want to take screenshots of in our app. In our example we&#8217;re going to take two screenshots of a table view.</p>
<p>Our first action scrolls the table view to the second row. Once <code>actionBlock</code> is called, <code>KSScreenshotManager</code> will take a screenshot and crop out the status bar.</p>
<p></p><pre class="crayon-plain-tag">KSScreenshotAction *synchronousAction = [KSScreenshotAction actionWithName:@"tableView1" asynchronous:NO actionBlock:^{
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:2 inSection:0];

    [[[self tableViewController] tableView] scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
} cleanupBlock:^{
    [[[self tableViewController] tableView] setContentOffset:CGPointZero];
}];

[self addScreenshotAction:synchronousAction];</pre><p></p>
<p>The next action is similar, but this time <code>asynchronous</code> is <code>YES</code>. This allows us to perform actions that take time to complete. Once the screenshot is ready, call <code>[self actionIsReady]</code>. This will take the screenshot and continue to the next action. Here we&#8217;re just changing the device orientation, but you might need to wait for other reasons, such as animations or network activity.</p>
<p></p><pre class="crayon-plain-tag">KSScreenshotAction *asynchronousAction = [KSScreenshotAction actionWithName:@&quot;tableView2&quot; asynchronous:YES actionBlock:^{
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:8 inSection:0];

    [[[self tableViewController] tableView] scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];

    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeLeft]; //programmatically switch to landscape (private API)

    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [self actionIsReady];
    });
} cleanupBlock:nil];</pre><p></p>
<p>Once the actions are created, we need to actually create the screenshots. We do that in <code>-[AppDelegate application:didFinishLaunchingWithOptions:]</code>:</p>
<p></p><pre class="crayon-plain-tag">dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    MyScreenshotManager *screenshotManager = [[MyScreenshotManager alloc] init];

    [screenshotManager setTableViewController:viewController];
    [screenshotManager takeScreenshots];
});</pre><p></p>
<h3>Driving the simulator</h3>
<p>So we have the screenshot actions set up, but we still have to manually change the project target and run the app in the simulator. Fortunately we can automate this too, thanks to WaxSim. Using <code>make_screenshots.py</code> we can generate screenshots for any combination of devices and languages. The version of <code>make_screenshots.py</code> included with the sample code runs for the 3.5 inch and 4 inch iPhone in English and German, for a total of 4 runs. You&#8217;ll need to change the variables in <code>make_screenshots.py</code> to make it work with your own project.</p>
<p>After running <code>python make_screenshots.py ~/Desktop/screenshots</code> in the Terminal, we have a fresh set of screenshots:</p>
<p><a href="http://ksuther.com/blog/wp-content/uploads/2013/02/screenshot-output.jpg"><img src="http://ksuther.com/blog/wp-content/uploads/2013/02/screenshot-output.jpg" alt="screenshot-output" width="575" height="355" class="alignnone size-full wp-image-312" /></a></p>
<p>That&#8217;s all there is to it! Any time you need screenshots, just run that script again and wait about a minute. For bonus points you can hook this up to your continuous integration server so you always have up-to-date screenshots.</p>
<h3>Getting fancier</h3>
<p>What you&#8217;ve just seen is enough to automate screenshots in your own app. However, it can be tricky to get your app just into the right state to make a screenshot. For example, <a href="http://flexibits.com/fantastical-iphone">Fantastical&#8217;s</a> screenshots had to have the exact same set of events and be running on a certain date. This took a bit more than just displaying view controllers and adjusting views. Here&#8217;s some additional details on what I did to get Fantastical&#8217;s screenshot process running smoothly. These won&#8217;t apply to every app directly, but hopefully it&#8217;ll provide some ideas.</p>
<h4>Faking the date and time</h4>
<p>The pesky thing about time is it won&#8217;t stay still. Not so helpful for screenshots of time-sensitive material such as calendars. Fortunately it&#8217;s easy enough to fake the date throughout an application without actually changing any code. <a href="http://cocoadev.com/wiki/MethodSwizzling">Method swizzling</a> to the rescue!</p>
<p></p><pre class="crayon-plain-tag">#import &lt;objc/runtime.h&gt;

@implementation NSDate (ScreenshotSwizzle)

+ (void)load
{
    SEL originalSelector = @selector(date);
    SEL newSelector = @selector(screenshot_date);
    Method origMethod = class_getClassMethod(self, originalSelector);
    Method newMethod = class_getClassMethod(self, newSelector);
    
    method_exchangeImplementations(origMethod, newMethod);
}

+ (id)screenshot_date
{
    //Today is November 14, 2012
    return [self dateWithTimeIntervalSince1970:1352894400];
}

@end</pre><p></p>
<p>Now the entire app thinks it is November 14 all the time. If you find yourself thinking &#8220;I wish I could change what this method does everywhere in the app,&#8221; think swizzling.</p>
<h4>Abusing private API</h4>
<p>There are all kinds of extra goodies available since this code isn&#8217;t going to the App Store. In the example above, I used the private <code>-[UIDevice setOrientation:]</code> to force the simulator into a difference orientation. In Fantastical, private API ended up being useful for setting up consistent calendar data. Rather than creating the events by hand using EventKit&#8217;s public API, <a href="http://stevenygard.com/projects/class-dump/">class-dump</a> revealed that <code>EKEventStore</code> had methods to load ics files already lurking in it. One private method later, I had events getting loaded from an ics file:</p>
<p></p><pre class="crayon-plain-tag">@interface EKEventStore ()
- (id)importICSData:(id)arg1 intoCalendar:(id)arg2 options:(unsigned int)arg3;
@end

NSData *icsData = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@&quot;Home&quot; withExtension:@&quot;ics&quot;]];
NSArray *events = [[self eventStore] importICSData:icsData intoCalendar:calendar options:0];</pre><p></p>
<p>This made it possible to create the events using a more sensible application and then feed the ics data straight into EventKit. Little things like this give even more time savings that you might not think of if you&#8217;re taking screenshots by hand. Again, take care to ensure you don&#8217;t let any private API leak into your App Store code.</p>
<h4>Loading network data</h4>
<p>Rapidly-changing network data can be problematic when you&#8217;re trying to make that perfect set of screenshots. While this wasn&#8217;t necessarily in Fantastical, using a mock object such as <a href="https://github.com/square/objc-mocktail">Mocktail</a> could make life a lot easier. (Disclaimer: I&#8217;ve never used Mocktail myself, but it looks handy.)</p>
<h3>Other options</h3>
<p>Prefer using the UI Automation instrument? <a href="https://github.com/jonathanpenn/ui-screen-shooter">UI Screen Shooter</a> may be of interest to you. I&#8217;m partial to my approach since I needed the additional control of setting NSUserDefaults based on locale, swizzling NSDate and loading specific calendar data on each launch. However, UI Automation may be more appropriate in some situations.</p>
<h3>Wrapping up</h3>
<p>Get the code for <a href="https://github.com/ksuther/KSScreenshotManager">KSScreenshotManager at GitHub</a>. As you&#8217;ve seen, you won&#8217;t be able to drop this code in and magically have automated screenshots in your own app. You still need to get your app into the right state to take the screenshots. The good news is that you only have to do it once. Happy automating!</p>
]]></content:encoded>
			<wfw:commentRss>http://ksuther.com/2013/02/24/automating-ios-app-store-screenshots/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>KSImageNamed: Xcode autocomplete for imageNamed</title>
		<link>http://ksuther.com/2013/01/22/ksimagenamed-xcode-autocomplete-for-imagenamed/</link>
		<comments>http://ksuther.com/2013/01/22/ksimagenamed-xcode-autocomplete-for-imagenamed/#comments</comments>
		<pubDate>Tue, 22 Jan 2013 06:18:59 +0000</pubDate>
		<dc:creator>Kent Sutherland</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://ksuther.com/?p=237</guid>
		<description><![CDATA[A few months ago I discovered and installed ColorSense for Xcode, which set my mind to thinking what other common annoyances or inconveniences be improved in Xcode. It took me about three and a half seconds to jump from colors to images, as Xcode doesn&#8217;t autocomplete imageNamed: calls. It&#8217;s impossible to remember the names of [...]]]></description>
				<content:encoded><![CDATA[<p>A few months ago I discovered and installed <a href="https://github.com/omz/ColorSense-for-Xcode">ColorSense for Xcode</a>, which set my mind to thinking what other common annoyances or inconveniences be improved in Xcode. It took me about three and a half seconds to jump from colors to images, as Xcode doesn&#8217;t autocomplete <code>imageNamed:</code> calls. It&#8217;s impossible to remember the names of all the images in a project, especially when there are a hundred or more images. Switching to the Project Navigator to check if the image is named <code>button-highlighted-pressed.png</code> or <code>button-pressed-highlighted.png</code> gets old quickly. Additional trips to check whether an image&#8217;s 2x representation is added to the project only makes matters worse.</p>
<p>Armed with a new idea, a few free hours, and <a href="http://stevenygard.com/projects/class-dump/">class-dump</a>, I sat down and started hacking. I figured out how to insert items into Xcode&#8217;s autocomplete lists, ran into a couple of roadblocks, quit for the day, and then promptly forgot about the matter entirely. And so the project sat and collected dust, as code is prone to do. Finally, last week I forgot the name of one image too many. So I now present to you KSImageNamed, an Xcode plug-in for getting the <code>imageNamed:</code> autocomplete that should have been there in the first place.</p>
<p><img src="http://ksuther.com/blog/wp-content/uploads/2013/01/KSImageNamed.png" alt="KSImageNamed in action" width="458" height="215" class="alignnone size-full wp-image-247" /></p>
<p>Want <code>NSImage/UIImage imageNamed:</code> autocomplete bliss in your copy of Xcode? Go clone and build <a href="https://github.com/ksuther/KSImageNamed-Xcode">KSImageNamed on GitHub</a>.</p>
<p>Hopefully this will save you a little frustration the next time you type <code>imageNamed:</code> and can&#8217;t remember the name of the image you were about to use. Even better, maybe this will get some people thinking about scratching an itch and making Xcode a little more pleasant to use. If there&#8217;s any interest, I may do a follow-up with some details on how the plug-in works so others can start hacking on Xcode themselves.</p>
]]></content:encoded>
			<wfw:commentRss>http://ksuther.com/2013/01/22/ksimagenamed-xcode-autocomplete-for-imagenamed/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Cleaning up and starting over</title>
		<link>http://ksuther.com/2013/01/21/cleaning-up-and-starting-over/</link>
		<comments>http://ksuther.com/2013/01/21/cleaning-up-and-starting-over/#comments</comments>
		<pubDate>Tue, 22 Jan 2013 04:35:18 +0000</pubDate>
		<dc:creator>Kent Sutherland</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ksuther.com:3000/blog/?p=216</guid>
		<description><![CDATA[It&#8217;s been almost two years since I&#8217;ve made any changes at all to this website, so it&#8217;s finally time to do something about the cobwebs that have gathered. There have been occasions where I&#8217;ve wanted a place to post something small and simple, but the sole orientation of this site towards Chax and Warp has [...]]]></description>
				<content:encoded><![CDATA[<p>It&#8217;s been almost two years since I&#8217;ve made any changes at all to this website, so it&#8217;s finally time to do something about the cobwebs that have gathered. There have been occasions where I&#8217;ve wanted a place to post something small and simple, but the sole orientation of this site towards Chax and Warp has sort of prevented me from doing so.</p>
<p>Almost 100% of my development work in the last two and a half years has been consumed by <a href="http://flexibits.com">Flexibits</a>, where <a href="http://twitter.com/macguitar">Michael Simmons</a> and I have been busy building <a href="http://flexibits.com/fantastical">Fantastical</a> and other apps. While this has resulted in some great new apps for everyone to use, it also means Chax and Warp have been completely ignored. Neither projects have been in active development for almost three years now, so it&#8217;s time to clean things up here and move those projects officially into storage. Functionally this means nothing is going to change, so this is more of an official acknowledgement of reality so I don&#8217;t have to feel guilty about ignoring them anymore.</p>
<p>Chax and Warp are still available for older versions of Mac OS X (10.4-10.6 for Chax, 10.5 and 10.6 for Warp), so they haven&#8217;t disappeared completely. The source code for <a href="https://github.com/ksuther/Chax">Chax</a> and <a href="https://github.com/ksuther/Warp">Warp</a> are also available on GitHub in case anyone ever wants to try to breathe new life into them. At the very least, the source code to Chax is an interesting case study in using the Objective-C runtime to make large-scale modifications to another application.</p>
<p>I&#8217;d like to think that someday I&#8217;ll bring back Chax in a very limited fashion, if only to scratch my own itches with the rather uninspiring experience that is Messages. That is what Chax originally started as, but the sheer number of features and additions made it harder and harder to maintain in the face of ever-faster system updates. If Chax were to ever come back, it would be a back-to-basics version, changing just the things that annoy me the most.</p>
<p>Keep an eye out here for future posts, probably mostly related to Mac or iOS development in some form.</p>
]]></content:encoded>
			<wfw:commentRss>http://ksuther.com/2013/01/21/cleaning-up-and-starting-over/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Warp 1.2.3</title>
		<link>http://ksuther.com/2011/03/07/warp-1-2-3/</link>
		<comments>http://ksuther.com/2011/03/07/warp-1-2-3/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 04:46:12 +0000</pubDate>
		<dc:creator>Kent Sutherland</dc:creator>
				<category><![CDATA[Apps]]></category>
		<category><![CDATA[Warp]]></category>

		<guid isPermaLink="false">http://ksuther.com/blog/?p=207</guid>
		<description><![CDATA[Fixed a crash that could occur when warping. Download Warp 1.2.2 Warp on GitHub]]></description>
				<content:encoded><![CDATA[<ul>
<li>Fixed a crash that could occur when warping.</li>
</ul>
<p><a href="http://www.ksuther.com/warp/downloads/Warp_1.2.3.dmg">Download Warp 1.2.2</a><br />
<a href="http://github.com/ksuther/Warp">Warp on GitHub</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ksuther.com/2011/03/07/warp-1-2-3/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Warp 1.2.2</title>
		<link>http://ksuther.com/2011/01/16/warp-1-2-2/</link>
		<comments>http://ksuther.com/2011/01/16/warp-1-2-2/#comments</comments>
		<pubDate>Sun, 16 Jan 2011 20:46:11 +0000</pubDate>
		<dc:creator>Kent Sutherland</dc:creator>
				<category><![CDATA[Apps]]></category>
		<category><![CDATA[Warp]]></category>

		<guid isPermaLink="false">http://ksuther.com/blog/?p=205</guid>
		<description><![CDATA[Fixed caps lock preventing Warp from activating. Warp no longer activates when in a fullscreen application such as a game. Download Warp 1.2.2 Warp on GitHub]]></description>
				<content:encoded><![CDATA[<ul>
<li>Fixed caps lock preventing Warp from activating.</li>
<li>Warp no longer activates when in a fullscreen application such as a game.</li>
</ul>
<p><a href="http://www.ksuther.com/warp/downloads/Warp_1.2.2.dmg">Download Warp 1.2.2</a><br />
<a href="http://github.com/ksuther/Warp">Warp on GitHub</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ksuther.com/2011/01/16/warp-1-2-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
