MacKuba

🍎 Kuba Suder's blog on Mac & iOS development

How to add icons to the menu bar on Yosemite

Categories: Cocoa, Mac Comments: 4 comments

Mac applications often add their icons to the notification area on the right side of the menu bar. That way they can show you some status changes by changing the icon image, and they can also save some space in your dock by removing the icon from there while still being easily accessible.

If you’re like me, you probably have quite a lot of those there:

The menu bar controls usually display their standard (preferably dark) icon on a standard background by default, and an inverted white icon on a blue background when clicked:

Read more »

A guide to NSButton styles

Categories: Cocoa, Mac Comments: 25 comments

⭐️ This post has been rewritten in December 2021 for Xcode 13 & macOS Monterey. (old version here)

Note (Oct 2023): The names of the buttons have been changed again in the SDK in macOS Sonoma - I will update this post once I have Sonoma on one of my Macs :)


When you’re building a native Mac app and you want it to feel like a part of the system, to have a UI that users who care about design will appreciate, it’s important to use the right kind of controls in the right places. Some features could be implemented visually in a lot of different ways, but only a few of them will “feel right”. This is even more important these days - with the influx of Electron apps that don’t even pretend they’re native, and not always well written Catalyst apps that often feel like something is missing there, an AppKit app written with care and attention to detail stands out from the crowd more than ever.

The macOS SDK has quite a lot of different controls available, and while this gives you a lot of built-in functionality for free, using them in the right way might be a bit more tricky than on iOS. This is especially true in case of the base button class, NSButton, which lets you choose from as many as 15 different styles, not counting the subclasses.

I originally wrote this post 7 years ago, shortly after OS X 10.10 Yosemite was released, changing the design significantly since the previous versions. The latest version of Xcode was 6.1, and if you were working on a Mac app interface and looked at the selection of available buttons there, you would see something like this:

Read more »

How to fix NTFS support on OSX Lion

Categories: Mac Comments: 13 comments

After I upgraded my Mac to Lion this month, I’ve noticed that my NTFS drives stopped working. I’m using NTFS on my Windows XP partition and on a WD external drive. I’ve previously used MacFUSE and NTFS-3G, which is probably the most commonly used solution for people who want full NTFS access on OSX (as you probably know, by default OSX only provides read only support). However, that doesn’t work anymore on Lion. The problem is that MacFUSE is not maintained anymore and doesn’t work with a 64-bit kernel which is used by default in Lion.

First Google results usually point you to commercial solutions, but I’m not willing to pay for something as basic as filesystem support, which, frankly, Apple should have provided themselves long time ago. If you want to avoid paying, the right way is to replace latest stable MacFUSE with something that works on Lion.

Based on a few blog posts and comments I managed to find a way that worked for me, so I thought I’d put it all here in one place for others. The fastest way IMHO is to install packages from the command line, because – at least in case of NTFS-3G – it’s hard to tell from the website which version is the right one. I’m going to assume you haven’t lived under a rock for the last couple of years and you’re using Homebrew, not MacPorts. It’s not completely automatic – you’ll need to do a few things in the terminal, but it shouldn’t take more than a few minutes in total.

Read more »

Installing Sphinx on MacOSX from ports

Categories: Databases, Mac, Ruby/Rails Comments: 4 comments

A few days ago I spent a couple of hours trying to install the full text search engine Sphinx on my work computer in order to use it in my current project. I’m posting the details here, maybe this will save someone some time…

Firstly, if you’re like me and you look for some kind of binary package (like .dmg) first – sorry, there isn’t one. This leaves us two options: compiling Sphinx manually from the source, or using a package manager like MacPorts. I always avoid the first method if I have any other option, so I tried the ports.

Here’s the first problem: Sphinx requires MySQL, and while I have it on the disk of course, I’ve installed it from a dmg package, not from ports – which means it’s in a different path than ports expect and they have no idea where that is. I got scary errors like:

$ sudo port install sphinx
---> Building sphinx with target all
Error: Target org.macports.build returned: shell command " cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.​macports.​org_release_ports_textproc_sphinx/​work/​sphinx-0.9.7" && make all " returned error 2
Command output: sphinx.cpp: In member function 'virtual const char* CSphSource_MySQL::SqlError()':
sphinx.cpp:9397: error: 'm_tMysqlDriver' was not declared in this scope
sphinx.cpp:9397: error: 'mysql_error' was not declared in this scope
sphinx.cpp: In member function 'virtual bool CSphSource_MySQL::SqlConnect()':
...

Read more »

Interface Builder tips and tricks

Categories: Cocoa, Mac Comments: 1 comment

I read Apple’s tutorial about Interface Builder this week. Most parts of it told about rather basic things and were quite boring, but I’ve learned several useful tricks from it. IB, like most of Apple’s applications, has lots of hidden features which aren’t obvious at first, and can only be found by experimenting, by accident or by reading about them somewhere. Here’s a few things that I’ve learned from the tutorial – some of them are such hidden features, some are just things that weren’t mentioned in any source I’d read before.

Read more »

Generating scaffold interfaces in Cocoa

Categories: Cocoa, Mac Comments: 0 comments

I discovered an interesting feature in Interface Builder a few days ago. It seems that it can generate a scaffolding UI for you based on a CoreData model. It works like this: first you have to design a data model in XCode model editor (which you have to do anyway if you want to use Core Data; if you don’t, it won’t make sense to draw the model only to get the scaffold UI, it will be faster to make it yourself…). Let’s say you have a model like in this picture:

XCode data model editor

Read more »

Missing controls in IB 3.1

Categories: Cocoa, Mac Comments: 0 comments

I’ve upgraded XCode and Interface Builder to version 3.1 recently (the update doesn’t appear in the system update, you have to download it manually, and it’s deceitfully hidden – you have to register at Apple’s developer portal to get it…). Today I’ve noticed that after the update some advanced controls were missing in IB. I had a vague memory of having a lot of additional categories of controls below the standard ones (some image views and Quicktime controls, for example), and I couldn’t find them there. This screenshot confirmed that I wasn’t imagining it. Not that I need them right now, but I might need them one day…

I was able to figure this out after a bit of googling, so I’m posting a solution here so that maybe I’ll save someone a little time. The thing is, for some reason IB forgot about some of its plugins; I think it has something to do with the “known issues” entry here in the release notes. Plugin files are located inside system frameworks. Anyway, to get them back, you need to go to IB’s Preferences → Plugins, and using the plus below the list add several framework bundles from /System/Library/Frameworks. The list more or less matches the list from the release notes, but you’ll have to experiment a bit (e.g. ImageKit and Quicktime plugins were hidden inside Quartz, and DiscRecording inside DiscRecordingUI). And that’s it, all advanced controls are available again.

"ls" on Mac and extended file attributes

Categories: Mac Comments: 10 comments

Yesterday while I was working in the terminal I noticed something unusual about the results of “ls -al” command:

Results from 'ls -al' command including at symbols (-rw-r--r--@)

What are those symbols? I googled for “mac ls at sign”, but most of the results told me that “@” means “symbolic link”. Well, all those files can’t be symbolic links, I’m pretty sure of that. So what are they?

Read more »