Tag: code

Customising NSAlert: accessory views

For a well-documented feature, NSAlert’s accessoryView feature takes a little bit of fiddling to implement. NSAlert is behind the standard pop-up modal alert window that’s familiar to everyone, often popping into the foreground and grabbing your attention, refusing to go away until you acknowledge its existence:

NSAlert boxes can, by default, display any number of buttons (c.f. the classic “Save/Delete/Cancel” triumvirate), but advanced features require a little more jiggery-pokery. This mainly comes in the form of its accessoryView property, which allows you to add an NSView to the alert proper. At first you might be tempted to programatically create an NSView, adding the required elements in init methods and the like, but it turns out it’s actually a bit easier to use nib files to hold all of that. This is how to do so.

Migrating MacRuby scripts to Objective-C

First signs of decay

After upgrading to Mavericks, I found that a few of my MacRuby scripts had stopped working. Apparently it’s due to some part of the optparse package, which breaks upon upgrading, and I’m not the only one getting the error. The issue has been open for about a month now, and there doesn’t appear to be any response from the devs.

This isn’t to say that the project’s defunct, but this has happened before to promising ruby-cocoa bridging tools. It’s symptomatic (I believe) of a more general trend, in which people build a cool bridge, but Apple has no responsibility to keep it working. When Apple upgrades various portions of the OS, these bridges stop working, which then mean that the devs have to scramble to fix their own products.

Desktop background on OS X 10.9 Mavericks

I upgraded to OS X 10.9 a week or so ago, along with everyone else in the Mac nerd world. And like everyone else in the Mac nerd world, something of mine broke. In my case, it was a small script that would alter com.apple.desktop.plist to daily change my desktop.

Essentially, you have no way in OS X of syncing desktop backgrounds between spaces. You can set desktops so that all your spaces have the same desktop, but if you want to cycle them randomly, the first time the OS changes them, they’ll be all different once again. The problem is not a huge one, but it fell into a particular category of being big enough to annoy me, and small enough that I could write a script to fix it.

Assign 0.4.0 update

A minor update to Assign.app tonight: Version 0.4.0 brings the ability to “drill down” into a folder. It’s something I occasionally found myself doing, expecting it to work, and it wasn’t like the right-arrow key was doing anything anyway.

Catalogue search times are quite slow when you get beyond ten characters or so. This is mainly because I’m constructing a “fuzzy string” with which to search the catalogue:

Opening Sublime Text files in other applications

Here’s a simple plugin for Sublime Text that you can modify to suit your own needs.

I often find myself using different plain-text apps for different purposes. Sublime Text is my go-to app for coding and technical writing, mainly due to all the usual factors: syntax highlighting, snippets, plugins and so on. However, I often find myself switching to Byword for longer-form writing, or just when I want a more prose-friendly environment. Unfortunately, Sublime Text lacks an “Open in…” menu item like you see in, for example, Notational Velocity. What it does have is incredible support for plugins, so I figured it wouldn’t be too hard to make one for my purposes.

Tabbed windows, take 2

After my previous post on how to do tabbed windows in Cocoa, a friend pointed out that I’m going about this all wrong, and using NSTabView is inefficient and introduces unnecessary overhead.

Turns out you can do this much more simply by just adding another NSView alongisde your current window:

Simple checklists with ruby and prawn

I recently finished reading Atul Gawande’s The Checklist Manifesto, which is an excellent book on why lists are good for your life. His comments on how to use checklists in everyday activities resonate with me, a chronic forgetter with a list of things to do every weekend so his bedroom doesn’t overflow with junk.

Gawande’s descriptions of checklists - simple, unadorned, and easy to read - made me want to make my own for various tasks that pop up in my life. At its heart, a checklist is a simple beast, so I started wondering if I could automate the generation of an A4 sheet of paper with suitable boxes and titles from, for example, a plaintext file.

Tabbed windows and NSToolbarItems

Update: I’ve since published a better way to do this whole thing. So give this article a read-through if you want, but check the link once you’re done here.

While tricky to explain, this sort of thing is all over the place in Cocoa applications:

Building a SublimeText command from scratch (and other useful bits)

Note: Since I started writing this, SublimeText3 came out. Hopefully I’ve caught any problems ST3 has with my methods.

SublimeText is my current text editor of choice. While I use a few others for specific tasks1, if I’m just going to chuck words in a file I’ll probably find myself using Sublime Text. One of the nice things about ST is the extensive plugin framework: a series of python files in a pretty simple file hierarchy makes for a bunch of hackability.

  • 1
  • 2
  • 3
  • ...
  • 5