Archive for the 'Creations' Category

Capture Cursor

Saturday, March 13th, 2010

Most people don't know how to get the cursor that's currently on the screen—a useful ability, especially if you're writing screenshot or screen-recording software. I've written an app that demonstrates the technique, or at least tries to.

It's a bit flaky. The API it uses, IOFramebuffer, doesn't tell me how many frames there are or what format they're in, so the app assumes ARGB in native byte-order and doesn't worry about frames. This gives wrong results more of the time than I like.

I've filed a request for a higher-level API, which would make the task much easier and the app much shorter.

I've posted a build in the repository's downloads area, in case you'd like to see it in action. If you want to build it yourself, you'll need to download SGHotKeysLib and put the source where the Capture Cursor Xcode project expects it to be.

Easy main-thread performing category

Saturday, February 13th, 2010

Anyone who's ever had to perform a message on the main thread knows how ugly the code can be:

[obj performSelectorOnMainThread:@selector(receiveAnswer:)
                      withObject:[NSNumber numberWithUnsignedInteger:42]
                   waitUntilDone:NO];

I've written a category that changes the above code to something much simpler:

[[obj performOnMainThread_PRH] receiveAnswer:42];

Notice that not only is the code much easier to read and to write, but you no longer need to box and unbox primitive values.

You can get the code, under a BSD license, from the higher-order main-thread perform repository.

Back when I originally mentioned my creation of the category on Twitter, Dave Dribin replied that he had already written one of his own. His is part of his DDFoundation framework, and requires DDInvocationGrabber (a fork of Jonathan Wight's CInvocationGrabber), also part of that framework.

My category requires nothing but Cocoa and is not part of a larger framework. That said, it's interesting to read in his code how the functionality of the Invocation Grabber makes his implementation nothing but a thin wrapper around it. (Also, his version lets you say waitUntilDone:YES.)

Nearest Neighbor Image Unit

Saturday, February 6th, 2010

I originally wrote this as an application using NSImage (with NSImageInterpolationNone), but decided to rewrite it as an Image Unit. So, here it is.

An introduction to Cocoa and Cocoa Touch

Wednesday, February 3rd, 2010

If you know someone who's recently taken up programming the Mac or the iPhone (or both), please give them one (or both) of these links:

As a frequent answerer of questions on Stack Overflow, I see certain patterns—not just frequently-asked questions, but also frequently-unasked questions: Things that are biting the questioner that they don't know about.

Sometimes they're thinking about things the wrong way (e.g., using property list objects where they should have a model). Sometimes there is a route to a solution (“my app is slow” “run Instruments”), but they don't know about that route. Often, they'll use wrong terms that are right on another platform (like “member variable”), like a speaker using their native language's pronunciation rules when speaking a foreign one.

To help people over these speed bumps, I've composed an introduction for new Cocoa and Cocoa Touch programmers. (Both of the above links redirect to it.)

If any part of it doesn't help them (i.e., is unclear or wrong), I'd appreciate it if you'd let me know, either here or by email.

Ship-It Saturday: Shorten URLs service

Saturday, January 30th, 2010

When posting links on Twitter, your Twitter client will automatically shorten the URLs to make them fit.

There are many, many general shorteners, including TinyURL, Notlong, Metamark, and Bit.ly. One of the complaints about these is that they hide the true destination of the link: From the URL alone, you don't know whether you're going to be educated, RickRolled, or worse. (TinyURL and Bit.ly both offer a way to preview the link, but that's not as easy as just looking at the URL.)

To help with this, several non-shortening-related websites have added their own shorteners that use their own domains, particularly for use on their official Twitter accounts or with a built-in post-to-Twitter feature.

The problem is that it's not always easy to tell what the shortened link will be. Flickr is among the most difficult: Their regular links use decimal numbers, but their shortened links use base-58, which is not a trivial conversion to perform in any programming environment I know how to use. (Not so easy as, say, decimal to octal.) It's certainly doable, but would require extensive tests to verify that your base-58 numbers match Flickr's. There's sample code, but it's in PHP, so if you're writing in anything else, that means porting it, which means (again) extensive tests.

So, rather than write my own shortener, it's much easier to just use Flickr's: curl the canonical long URL, then scrape the short one out of the body. (Yay for <link rev="canonical">!) I wrote a service to do this.

For Ship-It Saturday, I retooled it. No longer is it just a Flickr shortening service: It now handles YouTube, Amazon, and a few other sites as well. A single service invocation shortens all links to websites that have their own shorteners.

So, here you go: The Shorten URLs service.

finder, a command-line tool

Sunday, January 24th, 2010

Today's Ship-It Saturday is a command-line interface to the Finder.

The two most useful commands are:

  • finder reveal file, which will select the file in a Finder window, and
  • finder update (or updated) file, which will tell the Finder that the file has been updated.

The latter command probably is not too useful anymore, but the command-line tool should work on no less than 10.4, and could probably be recompiled for even older versions of Mac OS X, so you may still have a use for it.

CocoaHeads Lake Forest videos

Monday, January 18th, 2010

It's been in editing for over a month, but now, it's finally done. I've just uploaded the second part of last month's meeting of CocoaHeads Lake Forest. There's one more to go from last month, and then I can start posting the video from this month.

This one's a lot more random than the first one. Portions of my own presentation are only part of what you'll see in this video.

More long-term, I've created a channel on Vimeo for all past and future CocoaHeads LF videos.

Pointers tutorial 1.3

Saturday, January 16th, 2010

At long last, a new version of Everything you need to know about pointers.

The most significant changes are long-overdue corrections regarding declarations of const pointers and the difference between arrays and pointers. You can—and, if you learned how to work with pointers from this tutorial, should—read all of the changes in the delta between 1.2 and 1.3.

Application Locator

Friday, January 8th, 2010

This is a little one, inspired by a Growl discussion list thread. Enter the bundle identifier or name of an application, and Application Locator will reveal it in the Finder.

Translate Text 1.0.1

Tuesday, January 5th, 2010

The new version adds a Sparkle public key, which should fix updating. Since updating was broken in all versions before 1.0.1, you'll need to update manually from the Translate Text web page.

Ship-It Saturday: IconGrabber 2.0.1

Sunday, January 3rd, 2010

The last time I released a version of IconGrabber was only a week after Valve released Half-Life 2—way back in 2004. That game wasn't even on my radar then, since I couldn't run it on my PowerPC-based Mac!

Just over five years later, I've played all of the Half-Life 2 games and love them, and IconGrabber returns with some bug fixes and support for the new bigger icon sizes introduced in Tiger and Leopard. Version 2.0.1 is available from the IconGrabber home page.

Ship-It Saturday: Translate Text

Sunday, December 27th, 2009

Real artists ship.

Steve Jobs

With the idea that an application that's 95% finished and in active use is better than an application waiting for 100% in the seclusion of my hard drive, Ship-It Saturday is where I dust off a program that I have 95% finished, call it done, and just ship it already. I hope to make this a regular feature, although I have no idea how frequently I'll do it.

Today's winner is Translate Text, an app I wrote to make handling Adium feedback emails easier. Just select some text, then choose the service corresponding to the language it's in (or the auto-detect-language-and-then-translate service). A window will open with the original, a couple of language pop-up menus, and the translation.

Screenshot of myself invoking the French-to-English service through a contextual menu.

More information, both screenshots, and the downloads at the Translate Text web page.

RAM disks on Snow Leopard

Friday, October 23rd, 2009

Make RAM Disk still works, which is not surprising, considering it's based on a few built-in commands.

What's changed is that the disk images system is now 64-bit, so if you have a 64-bit-capable Mac, you can create a single RAM disk bigger than 2 GiB—you no longer need to make multiple RAM disks and RAID them.

TimeMachineGrowler 1.0.1

Saturday, September 5th, 2009

The new version of TimeMachineGrowler includes compatibility with Snow Leopard and a few fixes. Plus, I've created a Google group for it, so you can get news of any further updates there.

TimeMachineGrowler 1.0

Thursday, August 27th, 2009

Just in time for tomorrow's release of Snow Leopard, TimeMachineGrowler is an app that will tell you how long Time Machine takes to create a back-up by posting Growl notifications when the back-up starts and finishes.

One of the promised “refinements” in Snow Leopard is faster back-ups, so you may find it interesting to compare how long a back-up takes on your machine running Leopard to how long it takes on Snow Leopard (assuming, of course, that you haven't already abandoned Leopard for the Snow Leopard GM).

Copy UNIX path to Finder selection

Thursday, August 13th, 2009

UPDATE 2009-08-14: Or just use CopyPath, which looks like a much better implementation of exactly the same thing. Thanks to David Keegan, its author, for suggesting it in the comments.

The original post content follows.


This is a script application, which apparently you can drag into your Finder toolbar. (If it doesn't let you, you didn't drop it in the right spot. Finder is finicky about this. Keep trying.)

Once you've added it to your toolbar, you can just click on it to run it. The script will copy the UNIX path of whatever you have selected in Finder to the clipboard.

Inspired by a conversation with Alan Boyd.

Symbolicator 1.0.1

Friday, April 24th, 2009

It's two-thirds faster, it works on more crash logs, and thanks to Augie Fackler, it's now available from the Python Package Index. This means that you can just do this:

sudo easy_install symbolicator

If [you run a custom build of Python and] you don't want to install setuptools, you can always get the Symbolicator from its webpage.

Oh, and there will be a 1.0.2 to fix some issues. At the moment, I'm going back to working on Growl things, so I won't start on those for awhile; if you want to beat me to them, fork the project on Bitbucket, commit your fixes, and send me a pull request. (Make sure you co-ordinate your efforts on the ticket! I don't want to have to choose from two independently-developed fixes.)

UPDATE 2009-04-25: Clarified above that installing setuptools is only necessary if you have installed Python yourself. Thanks to Augie for pointing this out in his comment.

Half-Life 2 Photography

Thursday, February 19th, 2009

My challenge to you:

Take a screenshot in any of the Half-Life 2 games (including Portal), and make it look and feel like an artistic or journalistic photograph. (I don't mean filters; I mean framing and the scene itself.)

Here's my first contribution:

A scene of the observer looking out a grimy window on to a Combine autogun emplacement.

If you want to join in, take a photographic-looking screenshot, and submit it to the Flickr group.

A note about ClickToFlash 1.2

Saturday, January 31st, 2009

Christopher Bowns pointed out (thanks!) that Jonathan Rentzsch released ClickToFlash 1.2 yesterday.

This is the first version that incorporates any significant features from my fork. Specifically:

  • It now loads the Flash movie on mouse-up, not mouse-down.
  • It now draws the ClickToFlash view as concave when the mouse is down and within its bounds.
  • It now has a separator item in the contextual menu.

The first two of these came from my tree, a fact that I am very happy about. The last one he pulled from Troy Gaul's tree instead, but it makes no difference, as it's just an element in a xib document.

If you're using 1.1+boredzo, you don't need to upgrade. My version of 1.1 has all the features of his 1.2, plus the “Copy Address” contextual menu item and, of course, my own click-to-play symbol.

ClickToFlash 1.1+boredzo

Thursday, January 29th, 2009

My fork of Jonathan Rentzsch's adopted WebKit plug-in lives on, as I release my version of ClickToFlash 1.1.

So far, he has not pulled any of my changes into his tree, so the list of features unique to my version has only grown:

  • It loads the Flash movie on mouse-up, not mouse-down, giving you a chance to back out by moving your mouse cursor off of the movie placeholder.

  • It changes to a concave appearance when you press the mouse on the placeholder, making it look, as well as act, more like a button.

  • It has a better (IMO) click-to-play image. (Screenshots on the other post.)

  • It adds a separator menu item to the contextual menu. (New in 1.1+boredzo, and the menu itself is new in 1.1)

  • It adds a “Copy address” menu item to the contextual menu (along with another separator). (New in 1.1+boredzo)

  • It incorporates Jason Foreman's fix for websites such as thedailyshow.com. According to him, that simple change fixes ClickToFlash on a lot of websites; I can vouch for it on thedailyshow.com, at least. (New in 1.1+boredzo)

File: ClickToFlash-1.1+boredzo.zip

The installer application, source code, and MIT license.