3 min read

Making a macOS app

Making a macOS app

There are some things I’ve been wanting to write for a while that just don’t make sense as a web app. Since I’m primarily using macOS now (for leisure at least), I want a macOS app.

After much digging and despairing, the best solution I’ve found for creating GUI apps on macOS is actually Xamarin.Mac from Microsoft. There is definitely an irony there.

(And to be up-front here — it’s the state of things which is bad, not Xamarin.)

Swift

Swift is nice, but I can't even find basics like “how do I read the contents of a directory”. I’m sure that’s a lack in my Google-fu - it’s a fairly basic requirement - but if a web search doesn’t show up something like that, how’s it going to fare when I hit something more complicated?

Update: I’ve since found how to do this, thanks to a StackOverflow answer (tagged as iOS for extra fun). I had tried that answer before and it failed to build, with Xcode complaining that FileManager didn’t exist. Turns out you need to import Foundation.

JavaScript

I’m not un-familiar with JavaScript these days but none of the "JavaScript as an application" things I've looked at give me warm fuzzies.

(So far that’s mostly Electron and nwjs - there was something else but I’ve forgotten it.)

Update: Trey has pointed me at Tauri, which I now remember was what I looked at briefly before. I don’t remember why I discounted it before; it certainly looks better than Electron. I’ll give it another try and see how it goes.

Apart from the general thing about carrying around hundreds of megabytes of JavaScript interpreter, the whole thing just feels rather unwieldy. It reminds me of a phrase I came across a long time back.

Imagine a stegosaurus wearing rocket powered roller skates, & you'll get a fair idea of its elegance, stability & ease of crash recovery. - Lionel Lauer

Python

Using Python and Qt would be nice - but before I can use that they need to release a version which works on Apple Silicon. Last time I tried that wasn’t there. Though it didn’t tell me that, I found out when I tried importing the Qt library and it threw an exception at me.

Plus I think I’d have to buy a Qt licence to distribute whatever I wrote (assuming I don’t make it OSI compliant). I’d like to have a choice in that.

Python and Gtk - well, it's Gtk. If I wanted that kind of pain I’d just bang my head against the wall repeatedly, it would be quicker and easier.

Clojure

Clojure - I don’t know it well enough yet, but to be honest I didn’t want to be forced to lay my UI out manually in code anyway. There are some tutorials by folk who’ve gone that path but … no thanks.

(defn frequency-controls [{:keys [frequency]}]
  {:fx/type :h-box
   :alignment :center
   :spacing 20
   :children [{:fx/type :h-box
               :alignment :center
               :spacing 5
               :children [{:fx/type :text-field
                           :text (str frequency)}
                          {:fx/type :label
                           :text "Hz"}]}]})

The code above comes from Matthew D Miller’s website. No disrespect intended to Matthew - if you’re writing GUI code in Clojure that appears to be a perfectly functional way to do it. (Pun absolutely intended…)

Other options

Rust - I did some searching, but the summary is it’s not ready for mainstream GUI yet.

Go - also not yet ready for mainstream GUI building.

ObjectiveC - I know it would work, but I never could get my head around all the [notation :weirdness] that it involves.

C++ - just no. What kind of masochist are you? (That sounds like a one of those “twenty questions” quizzes from Facebook.)

Xamarin.Mac

So that brings us back to the start, so to speak. And I have to say the Xamarin team have done a good job.

I’ve followed the “Hello Mac” walkthrough. There’s a few places where the Xcode GUI has changed, but it was clearly written.

It integrates with Xcode to use the Interface Builder. Visual Studio takes care of all the plumbing behind the scenes, though, you don’t have to care about that. And the acid test - after finishing the walkthrough I was able to trivially extend the “Hello Mac” example to reset the counter, no Googling or puzzling required.

Conclusion

I’m glad I’ve found something that seems worth pursuing further, but I have to be honest that I’m a bit sad at the amount of effort it took.

Surely I must be missing something obvious? It can’t be that the tools to write GUI apps are that lacking, surely? Please do let me know (politely!), I’d like to have more options.