How to have users select a directory

Graham Cox

I’d stick with the button, because its clickability shouldn’t be in doubt.

The text field, if it’s just a label, is not generally assumed to be clickable, and if you show it as editable, that sends the message that you’re expected to type something. NSPathControl is also a good choice for displaying the path, since it deals with excessive length more intelligently than a text field, and also shows icons (optionally), which can be helpful. NSPathControl can be made an active control, but I don’t think it works very well for choosing a directory.

Also, consider the case of when no folder has been set. When an app is sandboxed, this is very often the case when your app first launches, since until you pick something you don’t have the necessary security privileges to display a path. After choosing a location, you would create a security-scoped bookmark to persist that choice, but on first run you can’t so that. So your text field will be initially blank, and only the button offers any clue that you’re expected to do something. You can of course back that up with a sheet alert that prompts you to pick a folder when that UI first appears and there’s no folder set. You should also set the placeholder text (of the text label or NSPathControl) to instruct the user to choose a folder - it will be displayed automatically when that path is empty.

Here’s all I do in one of my apps - this is a button and an NSPathControl used passively.


On 26 Sep 2019, at 1:49 am, Gabriel Zachmann via Cocoa-dev <cocoa-dev@...> wrote:

I am looking for a nice, intuitive way to let users select a directory.

Right now, I have a simple TextField in my GUI that shows the current path,
and a simple Button next to it that says "Change".
When users click on it, it opens an NSOpenPanel that is runModal.

This works fine, but I am wondering if there are more elegant methods.
For instance, whether it might be possible to dispense with the button,
make it obvious that users can click on the text field, and then open the NSOpenPanel.

Or are there any other neat ideas?

(I was stumbling across NSPathControl, but it is not clear to me whether that would be a good alternative,
and how difficult it might be.)

Thanks a lot in advance for all kinds of insights and hints.

Best regards, Gabriel