MiddleClickClose Updated For Future Safari Versions

08/31/2009 Update: For Snow Leopard compatibility, see here.

Yesterday Apple release Safari 4.0.3 which, of course, broke MiddleClickClose. Again. The problem lies in the file Info.plist that is part of the plugin. From what I read about SIMBL, good practices said that you should include a key called MaxBundleVersion whose value was the internal version number of the app you were patching. The problem is that every time Safari gets updated, Apple increments that number and SIMBL won’t load the extension any more, since it proclaims that the maximum version of Safari it should be loaded with is the previous version.

I usually play catch-up with Apple and get MiddleClickClose updated a day or two after a new Safari ships. I’ve decided to stop that and have removed the MaxBundleVersion from the Info.plist. This is, after all, a dirty hack, so why not make it even hackier?

If you re-download and re-install, you shouldn’t ever need to update it again. If you already have it installed, you can just edit the Info.plist file that will be in ~/Library/Application Support/SIMBL/Plugins/MiddleClickClose.bundle/Contents, removing the two lines that look like this

<key>MaxBundleVersion</key>
<string>5530.18</string>

Here are the new downloads

Scala Limerick

On the Java Posse mailing list, there’s a message thread consisting of limericks about Scala or other languages. While I don’t claim to be a poet, here’s my submission

There once was a lang called Scala
That was sweeter than juice from Odwalla
Whether foldLeft or foldRight
It it such a sight
To see Lists reduced down with such might!

I won’t win any prizes for that one, but I thought it was somewhat clever. Of course, ten seconds after posting it, I realized that it’s not a true limerick, because the fifth line is supposed to rhyme with the first two. Oh well. There goes my career as a poet.

MiddleClickClose for Safari 4.0.1

A day or so ago Apple released Safari 4.0.1 and bumped the version number in the process. Safari 4.0 was 5530.17, while Safari 4.0.1 is 5530.18. After installing the update, MiddleClickClose was still loading, even with the minor version mismatch. I don’t know if Safari only looks at the first part of the number when specified in an Info.plist for MaxBundleVersion, but just to be on the safe side, I bumped it to 5530.18 and have re-released it. If it’s working fine for you, don’t bother getting this version. That’s the only change I made.

Apple Doesn’t Seem To Want My Money

Yesterday, like six billion other people, I tried to pre-order a new iPhone 3GS from the Apple Store online. After trying multiple times getting multiple timeouts, I was finally given a message stating that they could not complete my request online, and that I needed to go to a brick-and-mortar Apple Store to complete it. This didn’t completely shock me since when I bought my first generation iPhone, I could not activate it through iTunes, and instead had to visit an AT&T store.

Shortly afterward, I received an email from concierge@apple.com, with this text

Thanks for starting your iPhone purchase online. To finish the process, come to the store you selected and look for a Concierge in an orange shirt. We’ll help you complete your purchase, activate your new iPhone, and set it up for you.

Apart from the fact that I didn’t select a store, this was in sync with what the online store told me. A pain to have to visit an actual store, to be sure, but it didn’t sound like it would be too painful.

So today, I drove to the mall and visited the Apple Store. As soon as I entered, I spied an orange-shirted “concierge” and approached her. “Hello,” I said, “I tried to preorder an iPhone 3GS yesterday online, but it said it couldn’t do it, and I needed to seek out an orange-shirted person at an Apple Store. Can you help me with this?” She looked pained as she responded, “I’m sorry… we don’t actually have a system in place to pre-0rder the 3GS.” She went on to say that they did have a pre-order system for when the 3G was launched, and she assumed they would move that system over for the 3GS, but they had nothing now, and I should come back on the 19th. She also said that “lots” of people had been coming in today, who had also been told to visit a store to complete their purchase.

That just sucks out loud.

I’m trying really, really hard to throw money at Apple and they just won’t take it. They clearly underestimated how many people would try to pre-order online yesterday, otherwise they would have had more server bandwidth to handle it. The fact that they sent me (and others) an email telling me to go to a store to finish the process, when they have no such process in place, is just sloppy. I’m not happy about this one little bit, and I want people to know about it.

Does this mean I’m not going to buy a 3GS and, instead, go with a Pre or something else? Of course not, and Apple knows this….

Scala Gets Operator Overloading Right

02/20/2010 Update: I took this blog post and turned it into a presentation to the Atlanta Scala User Group, which I gave in January 2010. The slides from that presentation are here.

05/31/2009 Update: As Mads Andersen pointed out, in the example below, I had the Complex multiplication wrong. As I was working through the example in the book, I typed it incorrectly. I could argue that this blog post was not about my mastery of complex numbers, and was actually meant to show how operator overloading works in Scala, but in the interest of all-around correctness, I have updated the code to contain the proper implementation of complex number multiplication, and I have worked out the examples by hand using the formula on the Wikipedia page to ensure their accuracy. Now, on to the original article.

I’ve been intrigued by Scala for a while now, and I’m finally taking the time to learn it. As I was reading in my book yesterday, I came to the section on operator overloading. Now, this is a topic that developers who’ve been exposed to it feel very strongly about. It’s not quite as rough a discussion as vi vs. Emacs, but it’s close. Some say that operator overloading makes for more elegant code. Some say it just confuses things. I’ve always been in the elegant camp. I think if you can provide operators for your own classes that work intuitively, you ought to be able to do it. In Java, think about how nice BigDecimal would be to use if you had + and – instead of add() and subtract(). Of course, as with anything of power, you have to be careful not to abuse it. It would make no sense to provide a + operator on a Date class, since adding two dates together makes no sense. You have to be smart about it, but having the ability to provide operators for your own classes performing intuitive functions is a good thing.

So as I’m reading the section on operator overloading, it was nice to see that even though you can override the standard mathematical operators, Scala still maintains the proper precedence that everyone is used to. By this I mean that a + b * c will execute the multiplication first, then add the product of b and c to a. The reason this is interesting is because another language that I still love, Smalltalk, does it wrong (or at least, completely differently), and not just for overloaded operators. Smalltalk has no precedence for mathematical operators at all, ever. So a + b * c will execute the + operation on a, passing in b, and then execute the * operation on that result, passing in c. Always. Thus, 2 + 3 * 5 = 25 in Smalltalk, even though it should equal 17. To get 17, you’d have to write the equation as 2 + (3 * 5). I always found that strange.

The canonical example for operator overloading is a class to represent Complex numbers. I will not break with tradition and will, in fact, steal borrow the one from the book. Here, then, is the definition of the Complex class

class Complex(val real:Int, val imaginary:Int) {
    def +(operand:Complex):Complex = {
        new Complex(real + operand.real, imaginary + operand.imaginary)
    }

    def *(operand:Complex):Complex = {
        new Complex(real * operand.real - imaginary * operand.imaginary,
            real * operand.imaginary + imaginary * operand.real)
    }

    override def toString() = {
        real + (if (imaginary &amp;lt; 0) &quot;&quot; else &quot;+&quot;) + imaginary + &quot;i&quot;
    }
}

Notice that we have overridden both the + and * operators. They each take another instance of Complex as an argument, do the proper operations and return a new instance of Complex as their result. Just as you would expect. Now, to exercise these operators, we have this

val c1 = new Complex(1, 2)
val c2 = new Complex(2, -3)
val c3 = c1 + c2

val res = c1 + c2 * c3

printf(&quot;(%s) + (%s) * (%s) = %sn&quot;, c1, c2, c3, res)

val res1 = c1 + c2 * c3 + c1 * c2

printf(&quot;(%s) + (%s) * (%s) + (%s) * (%s) = %sn&quot;, c1, c2, c3, c1, c2, res1)

Lines 5 and 9 are the interesting parts. The result of running these statements looks like this

(1+2i) + (2-3i) * (3-1i) = 4-9i
(1+2i) + (2-3i) * (3-1i) + (1+2i) * (2-3i) = 12-8i

which is exactly what you’d expect.

Now, C++ people are probably saying, “But C++ has always done it right!” Indeed. But languages like Smalltalk and Scala are far more fun to work in.

Skype For iPhone Is Full Of WIN!

We’re on vacation in Colonial Williamsburg, and the AT&T signal in and around our hotel sucks! This seems to be a common theme for me. At home, I have next to no AT&T signal. I swear, if it weren’t for the iPhone being such a loverly machine, I would never have gone with AT&T. Anyway, so we’re here in Williamsburg, and in the hotel, there is no cellular signal at all. But there is free, and fast, WiFi. So I fired up the Skype program on my iPhone and would you believe it worked a treat? It did. I have now made two calls with it. One to a restaurant in town, and the other to my brother-in-law back in GA to check on our dog. Both calls were crystal clear, with no lag or dropouts. I only have a 1G iPhone, so I can’t test it over the cellular network, but over WiFi, it was darn near perfect. I have a Skype unlimited subscription, so these calls were essnetially free. In any event, it was better than paying the $0.75 the hotel would have charged me for each call, plus whatever rate the local phone company charged. But beyond the cost, it was just plain cool!

I’ve been a fan of Skype for several years and we use it extensively where I work. I call into meetings and conference calls using it all the time, and I only very rarely have problems. I am now equally impressed with Skype for iPhone. Great job, guys! Keep up the great work.

Smiley

Help Me With iPhone Dev Graphics Question, Please

Usually when I learn a new programming language or framework, I am plagued by the fact that I can’t think of anything to build with it, or I can only think of things that are too difficult. With iPhone development, I have two ideas for apps, both of which should be fairly easy to write. I’ve gotten a good start on the first app, but now I’ve hit a roadblock, and I’ve been stuck here for a while. I thought I’d ask for help.

Obviously I can’t disclose too much of what the app does, since I do eventually want to sell it in the App Store. Essentially, it allows for a very specific type of photo manipulation. I’ve got the basic UI built, and I’ve hooked into the camera framework, so you can either take a new photo, or use one you already took. I am displaying the photo in the main window, currently scaled to fit, but I will eventually add zoom and pan. I have the code written that allows the user to define a region of the photo to work on, by drawing a rectangle or ellipse. I draw the shape using Quartz 2D, which results in a red rectangle or ellipe drawn on top of the photo. So far, so good.

This is where I’m stuck. I need to do “something” to the bits in the photo in the region defined by the rectangle or ellipse and, at some point, a freehand shape. (Obviously I can’t reveal what the “something” is.) So, I have looked through the Quartz 2D docs and am trying to figure out how I can

  1. get the bits in the region defined by the user’s drawing
  2. swizzle the bits with my secret sauce to produce the desired effect
  3. get the swizzled bits back into the photo for display to the user

And here I sit. I have never done anything with graphics before, so this is all completely foreign to me. I can’t see how to do any of those three steps.

The next question, then, is should I be using OpenGL ES instead of Quartz 2D? The iPhone dev book I have taught a little bit of both, and the OpenGL stuff looked far more complicated than Quartz, which seemed like overkill for my situation. I don’t know.

I think I can accomplish what I want by creating an image mask, applying that to my original image, and then displaying the new image, but the mask creation function, CGImageMaskCreate, has me confused. I get most of the parameters, but I don’t understand the CGDataProviderRef parameter. Can anyone offer any sort of pointers to get me moving again? Are there any really in-depth Quartz 2D tutorials? The Apple docs on Quartz that I’ve read are very basic, and don’t really give examples.

Thanks for any help or pointers. I know I haven’t given you much to work with.

ExportToArchive *Does* Work With iPhoto ’09

I just installed the iLife ’09 suite, which includes version 8.0 of iPhoto. While I haven’t had time to try out any of the new features, I did check to see if my ExportToArchive plugin still worked. I’m happy to report that it does still work. If you already had it installed, you don’t have to do anything; it will just work. If you don’t have it installed, the installer works with the latest version of iPhoto just fine.

If you encounter any problems using ExportToArchive with iPhoto ’09, please let me know.

Huzzah! MiddleClickClose Working In Safari 4!

08/31/2009 Update: For Snow Leopard compatibility, see here.

08/13/2009 Update: It should now work with all future versions of Safari without having to update it again. Read about the change here.

06/09/2009 Update: Apple released the production version of Safari 4 yesterday at WWDC. I have just updated the plugin distribution, so if you download it now, it should work. If you already have it installed, follow the directions below for changing the version number to 5530.17 and your old installation should work. If you don’t yet have it installed, follow the directions here.

Thanks to Sylvain Frébourg, MiddleClickClose is now working with Safari 4. The fix is quite simple: change the MaxBundleVersion in the Info.plist file from what it was, to 5528.16. I know that I tried that, because I could see warnings about an incorrect version whilst watching Safari start up on the console. I must have changed something else at the same time and not realized it, because no matter what I set the version to, it wouldn’t load. Anyway, I reverted my SIMBL install and my SIMBL plugin directory from back in January using Time Machine, made the version number change, and now it works. It helps to be methodical, and I was not.

So, there are two ways you can go about getting it working for you. You can edit ~/Library/Application Support/SIMBL/Plugins/MiddleClickClose.bundle/Contents/Info.plist, changing 5525.13 to 5528.16 5530.17, or you can download a new zip file and re-install. Either way should work.

If only Apple would build this functionality into Safari itself…

No MiddleClickClose for Safari 4

06/09/2009 Update: I thought I’d updated all the pages on my blog about MiddleClickClose, but I missed this one. It now works with Safari 4. Read about it here.

At least, not yet. I installed the Safari 4 beta this morning to check the compatibility of my MiddleClickClose extension. As someone else noted, it doesn’t work. I poked it a bit to see what I could see, but it’s still not loading. I don’t have time right now to try to figure it out, but I’ll try to take another whack at it this weekend.

Wanna know what I think of the beta, after about 15 minutes of playing with it? Of course you do. First, let’s analyze the list of what’s new. Right off the bat, I noticed these:

  • Top Sites: Opera did it a few years ago and called it Speed Dial
  • Tabs on Top: Chrome did it last year and did it much better
  • Cover Flow: Hey Apple, I think you’re overusing Cover Flow
  • Smart Address Field: Firefox and Chrome both have this
  • Smart Search Field: Firefox and Chrome both have this

I point these out because the press release from Apple about Safari 4, shown here at CruchGear, described these features as “innovative.” They are only innovative for the first browser to implement them, so I guess we have to give points to them for Cover Flow, but the others are just Apple playing catchup.

What’s still missing? Decent extension support, for one. Firefox has a rich set of extensions that do all sorts of cool things. I only use a few, but I wouldn’t want to browse without them. Technically it’s possible to write extensions for Safari, but it’s essentially an unsupported, filthy, dirty hack. While Firefox’s extension mechanism is a clusterf*ck of obscure files and object relationships, at least it’s documented and supported.

And of course Safari still doesn’t support closing of tabs with a middle-click. But I guess that goes back to Apple’s insane devotion to single-button mice.

Speaking of tabs, their implementation of “tabs on top” sucks compared to Chrome’s. With Chrome, there’s still about half a centimeter of title bar above the tabs for moving the window around and/or bringing it to the foreground. In Safari, the tabs go all the way to the top of the window, so if you have more than one tab open, you no longer have a title bar to grab. Yes, clicking-and-holding on a tab will let you move the window, but if you just wanted to bring the window to the foreground, if you clicked on a tab other than the one that was on top, you would end up bringing that tab to the front as you brought the window to the foreground, which isn’t what you wanted to do. But, truth be told, I don’t like tabs on top anyway. I was sort of interested when Chrome did it, but after using it for a while, I’d rather keep them where they’ve always been. (This article explains how to make Safari 4 move its tabs back below the address bar.)

As for Cover Flow, Apple is using it all over the place, and it’s getting old. I have no desire to see my bookmarks in Cover Flow mode. I know what my bookmarks are, thus I don’t need pictures to jog my memory.

Oh yeah, bookmarks. From what I can see, there is still no way to sort bookmarks. Yes, you can drag them into the order that you want, but that’s crap. I should be able to easily sort alphabetically by name, without resorting to manually dragging them into the order I want. Firefox does this with a right-click menu….

It’s not all bad, of course. From what Apple says, and from what I’ve heard, the JavaScript engine is blisteringly fast. I’ve always been impressed with Safari’s JavaScript speed, so improvements in this department are gravy. And for those who use Safari on Windows (I’ve never understood why anyone would, but who knows?), you finally have a Windows look & feel, so it doesn’t look like a Mac app running on Windows. That’s as it should be; I don’t like L&F pollution.

This is a beta release, so some of these things could change. I would really like to see official support for middle-click closing of tabs and bookmark sorting but I’m not going to hold my breath.