Missing features in the iOS Activity app

I’m sort of amazed we’ve made it as far as we have without these two features being built in:

Sick days. Sometimes we get sick! It would be pretty great to not lose a streak because I have a really bad cold.

Rest days. This is the big one. One day a week, it would be nice if my calorie goal could automatically be a little lower. It’s very common for workout programs to have a day per week that is to be at a lower intensity.

There’s almost certainly apps that can incorporate this somehow – although I’m not sure how to reset the calorie goal for a single day, one assumes there’s an API for it.

So why don’t we replace AppleScript?

So AppleScript sucks. What’s the alterative?

I don’t get why Apple hasn’t seriously entertained a “next generation” scripting engine, in particular one based on JavaScript. All the things are there:

There’s the “canonical” JavaScript OSA component but it doesn’t fit the criteria: it uses Spidermonkey, not Squirrelfish/JavaScriptCore. Still, its API is pretty spot-on (since it’s an OSA component). It’s also pretty old.

JSTalk is another contender. It’s sort of the opposite number of the JavaScript OSA: it uses entirely modern, native components – stuff Apple almost literally has laying around – but does not feature an OSA-compatible API (as near as I can tell anyway). But, it’s modern and very friendly with Cocoa.

The sweet spot is the fusion of the two; the “already works on top of an OSA layer” of the former and the “all the modern stuff” of the latter.

Someone at Apple please make this happen! Make scripting the Mac awesome.

An example of why Applescript is utterly awful and must be replaced

A while ago, I attempted to resolve the problem in Safari’s Delibar extension, wherein it can’t do what the Chrome extension can: automatically put the selected text into the ‘notes’ field.

I failed.

In part I failed because of Safari, and the way it structures extensions. Briefly, Safari uses a sort of separation-of-concerns model, so what a particular piece of an extension can access varies. Getting the selection is really hard because you need to use proxying and messaging to communicate between the current page, the extension’s “page”, and any resources.

I gave up because it sucked and wasn’t fun.

I had another thought: use Applescript to get the selection and pass it to the Delibar app itself! GENIUS!

The tl;dr here is “Delibar isn’t scriptable” so none of this matters, anyway.

Safari’s Applescript dictionary doesn’t include the term “selection”. To the best of my knowledge, you cannot use Applescript to get the selection of the current tab. Oh ….. kay.

So, the next logical step is to use JavaScript, because I know it has the ability to get the selection AND I know that there is a ‘do JavaScript’ command in AppleScript for Safari. Now we’re cooking!

Here’s the relevant bits from the dictionary:


do JavaScript (verb) Applies a string of JavaScript code to a document.


and the example:


set theResult to do JavaScript unicode text ¬ in tab


Makes sense, right? Sure. So you’d pretty much imagine that it works just like this:

tell application "Safari"
    set selectedText to (do JavaScript “window.getSelection()” in current tab of window 1)
end tell

Always returned null. Always. I then tried hundreds of combinations of more-or-less JavaScript, including:

  • adding a return
  • wrapping it in an anonymous function
  • using document instead of window
  • banging my head against the desk and cursing myself for ever having these sorts of thoughts After lots of searching, I discovered the completely obvious answer:

    do JavaScript “(”+getSelection())”

That’s a double-quote, left paren, single quote, single quote, plus, then the function and a closing quote.

Of course. Completely obvious. Note that removing the single quotes and concatenation operator doesn’t work. So “(foo())” doesn’t work, but “(”+foo())” does. I found two places that say it does work, but I can’t make it happen in the latest Lion and Safari.

How the hell do you even arrive at that as a logical place. And how do you expect regular people, ostensibly the target market for Applescript, to arrive at that conclusion?

Applescript is goddamned awful.

In which I play around with Vico

For many the holy grail of text editors is Textmate. In a very short time it became an indispensable tool for many, many programmers and sysadmins.

Then it stagnated horribly, it gets updated perhaps once per year (and then only to keep it running on the new OS release), and god forbid you find a bug: it will probably never be fixed.

(As I write this there is an alpha promised by Xmas. Many are understandably cynical about this.)

A bunch of projects started up to fill the vacuum created by TM2’s vaporware status. Without sounding too negative on what was an incredible amount of work, they’ve managed to re-implement much of TM1 in the time it took to get TM2 to alpha status. That said making your app compatible with the huge TM1 ecosystem (and what may be the TM2 ecosystem) is an obvious good design call.

Anyway, the two I had immediate access to are Vico and Sublime Text 2. More on Sublime Text 2 later.

To reduce it to the simplest description, Vico is a vi implementation in Cocoa (or at any rate, Mac-native) that is mostly TM-compatible (themes and bundles).

(Also note: I’m sort of unfairly conflating vi and vim here. Pedants, don’t freak out. Hopefully you’ll get what I mean.)

Whether or not you consider vi’s modal editing a plus or minus is not really even worth debating. If you don’t like modal editing, don’t bother to even try any modal editor.

Vico supports a pretty finite subset of vi commands, but enough that you’ll preserve basic muscle-memory when editing. As near as I can tell, commands aren’t as “composable” as a real vi, but that’s where the bundles take over.

Vico supports a subset of TM bundles, so you can probably drop in some functionality that would normally be done with vim macros or scripts.

You can also “drive” Vico’s functionality with built-in scripting using the Nu language. Nu is the (perhaps unholy?) fusion of LISP and Objective-C/Cocoa.  And example of using Nu scripting to perform an editor task (automatically hard-wrapping text in this case) is on the Vico blog.

Is that any better than Vim script, or ELisp? I dunno. Vico seems like too much mashed together. It’s in a weird place: if you’re determined to retain modal editing, why not just use MacVim? Well, MacVim is … not so much ugly as plain. So, assuming the creator can keep up with the state of the art enough to keep the users happy, it’s a nice way to appeal to modal editor junkies who somehow don’t fancy MacVim.

But what of the people coming from TM? Isn’t modal editing a huge change, even if it lets them keep some of their workflow? OK, you’re addicted to some set of TM features, but hopping into the world of modal editing seems like as big a jump as switching to some other editor (BBEdit, etc).

Anyway, Vico is an interesting project and I sincerely hope it stays around for a long time: I’m hugely in favor of taking “venerable” Unix concepts and wrapping them in modern clothes.


How to enable the FTP server (ftpd) in Lion: PLEASE DON’T

TUAW has a HOWTO on enabling the FTP server in Mac OS X Lion.

Please don’t.

FTP is insecure. Your password can be the single-most unbreakable string in the universe, but it doesn’t matter: it’s sent out over plain text. Moreover, anyone who’s been in the sysadmin game for more than 12 minutes has seen just about every FTP server get cornholed, literally cornholed, multiple times by securtity flaws.

The best thing the “technology community” can do is to actively discourage its use.

FTP over SSL is a better interim solution, if keeping “pure” the FTP protocol is required.

And enough about the damn “extra overhead” of SSH or SSL. We’re talking about a few bytes here, esp. when you’re on a LAN.

The sooner FTP dies, the closer we are to a world of endpoint secure protocols.

TextMate to BBEdit switcher’s guide: BBEdit has command-t now! (well, sorta)

For the full details, see here:  https://groups.google.com/d/topic/bbedit/J5YUlmHsVvM/discussion

Now, this feature is wonderful if you’re a long-time BBEdit user. It’s pretty extra awesome if like me you can only run PeepOpen on some of your Macs. And, for switchers looking for a native way to replicate their beloved cmd-t, it’s not bad.

That said I can totally understand why switchers would say “Not the same, not what I want/need”. My dream was to see them re-use the same dialog as the “Insert Clipping” window, which is just like (or damn near, in any event) TextMate’s window. PeepOpen includes extra functionality like showing SCM status.

Still, you can bind it to cmd-t and it’ll work close enough that your muscle memory might not get too confused. And be sure to check out the even more recent betas; they’ve been doing some big performance improvements (one of the reasons I have always kept BBEdit in my Applications folder, even when I’m trying out another editor or using an IDE for stuff like Java).

Safari 5.1 and “random reload”

So by now, you probably have an iPad. Right? There’s like, eleventy-billion of them sold so far, or something.

At some point you’ve probably been browsing around on the web, and then decided to play some Angry Birds, then back to web browsing. You open up Safari, and there’s the page you were reading; or at least there will be in a moment, because it just reloaded. Some times you can have a couple of “tabs” open, and visiting each in turn forces a page reload.

It’s incredibly annoying, but it makes sense: there’s precious little memory – real and virtual – and so some algorithm decides if a page should be kept in cache or flushed.

Well, Apple decided this was SO. INCREDIBLY. FUCKING. AWESOME. they decided to include it in Safari 5.1 for OS X. If I was using Lion to type this, I’d include the little shit icon/emoji.

Presumably this is some way to stop shitty JavaScripts from leaking and beachballing the entire OS. Or maybe they just thought it “just worked”.

Suffice it to say, many people aren’t happy. It’s finally gotten to me, having had a page reload in front of me while I was using it, with no other tabs open. That’s right: Safari had exactly 1 window with additional tabs and I got a page reload whilst flipping between my editor and the page o’ documentation.

Scuttlebutt is that disabling Java fixes it. I don’t know; in any event I have mission-critical services for work that require both Flash and Java, so I guess I am sort of screwed.

This brings up my eternal gripes with Firefox and Chrome: they annoy me to NO. END. As an example, I can’t get Chrome to set the icon in the Downloads folder, so whatever I last downloaded – disk image, picture, document, whatever – is the default white rectangle in my Dock. Always. That sort of makes the Downloads folder pointless (as a Dock item, anyway, in my humble but correct opinion). I tend to use it rather a lot, so having it not work is a giant poke in the eye.

There’s about 20 other things about Chrome I can’t seem to find an extension to correct. I honestly don’t see how people use it, on Mac OS X anyway, because it’s just covered in sharp edges. Is there anything more popular and yet, more warty and unpleasant?

Oh, right. Firefox. Don’t get me started: every time I open it, some extension is disabled for some reason or another. Now they’ve unveiled a plan to make that worse which is pretty great. I’ve only just figured out how to convince Firefox to stop grabbing the default client preference on my Mac – years after I’d decided Transmit was the best ever.


The point of this rant is that I’m pretty unhappy now with every browser out there. If I can’t find the switch for Safari’s “use the ungodly amounts of RAM I can buy cheaply” setting, what the hell do I do?