What is the procedure to install a command line tool (example DefaultBrowser)?

I want to install a command line tool called defaultbrowser, which I plan to integrate into a keyboard maestro macro shell script.

My problem is that I have no clue on how to actually install the command tool and not even in which directory it should be installed.
I don’t understand the install, make and make install directions below. I understand the defaultbrowser chrome part which I will integrate into a shell script.
thanks in advance for your time and help


Command line tool for setting the default browser (HTTP handler) in macOS X.
Build it:

Install it into your executable path:
make install


Set the default browser with, e.g.:
defaultbrowser chrome

This is the defaultbrowser/src/main.m

// main.m
// defaultbrowser

#import <Foundation/Foundation.h>
#import <ApplicationServices/ApplicationServices.h>

NSString* app_name_from_bundle_id(NSString *app_bundle_id) {
return [[app_bundle_id componentsSeparatedByString:@"."] lastObject];

NSMutableDictionary* get_http_handlers() {
NSArray *handlers =
(__bridge NSArray *) LSCopyAllHandlersForURLScheme(
(__bridge CFStringRef) @“http”

NSMutableDictionary *dict = [NSMutableDictionary dictionary];

for (int i = 0; i < [handlers count]; i++) {
    NSString *handler = [handlers objectAtIndex:i];
    dict[[app_name_from_bundle_id(handler) lowercaseString]] = handler;

return dict;


NSString* get_current_http_handler() {
NSString *handler =
(__bridge NSString *) LSCopyDefaultHandlerForURLScheme(
(__bridge CFStringRef) @“http”

return app_name_from_bundle_id(handler);


void set_default_handler(NSString *url_scheme, NSString *handler) {
(__bridge CFStringRef) url_scheme,
(__bridge CFStringRef) handler

int main(int argc, const char *argv[]) {
const char *target = (argc == 1) ? ‘\0’ : argv[1];

@autoreleasepool {
    // Get all HTTP handlers
    NSMutableDictionary *handlers = get_http_handlers();

    // Get current HTTP handler
    NSString *current_handler_name = get_current_http_handler();

    if (target == '\0') {
        // List all HTTP handlers, marking the current one with a star
        for (NSString *key in handlers) {
            char *mark = [key isEqual:current_handler_name] ? "* " : "  ";
            printf("%s%s\n", mark, [key UTF8String]);
    } else {
        NSString *target_handler_name = [NSString stringWithUTF8String:target];

        if ([target_handler_name isEqual:current_handler_name]) {
          printf("%s is already set as the default HTTP handler\n", target);
        } else {
            NSString *target_handler = handlers[target_handler_name];

            if (target_handler != nil) {
                // Set new HTTP handler (HTTP and HTTPS separately)
                set_default_handler(@"http", target_handler);
                set_default_handler(@"https", target_handler);
            } else {
                printf("%s is not available as an HTTP handler\n", target);

                return 1;

return 0;


You’re going to need XCode and the terminal. These should give you the background on self-compilibg your own application from that code.



1 Like

thank you. I think that I am way above my head.

Does it make sense to install the command line tools as per

If yes, after that, how do I add the specific defaultbrowser tool ?

thanks again very much for your help

I’ve always installed it alongside the full version of XCode, but yeah, those instructions look fine, and as you should be able to see from the list of utilities the article lists, it includes make .

You run make against the makefile they give you on GitHub, alongside the source code, and that gives make the instructions to compile the source code into the executable you want. It really should be that straight forward.

Then copy the resulting application to wherever you want in your path (see details I shared with you earlier).

Hopefully you can follow that, if not, I would suggest maybe taking advantage of SUMMERFEST2020, and grabbing a copy of Joe Kissel’s Take Control of the Mac Command Line with Terminal and getting comfortable with the Mac command line. It’ll open up an entire UNIX-y world of automation for you.

Hope that helps.

1 Like

thanks very much ! I bought Joe Kissel’s book and am now sure that I can work it out … thanks to your help !

What are you intending to do with this?

I think it would be a lot easier to use something like

1 Like

just to show you that I did indeed order the book as you suggested

thanks very much. I did not know about those apps. I was looking for something I could integrate into keyboard maestro macros which is why I was looking at defaultbrowser