Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save getaclue00/d52c4d3c6877738b3478d50613434ffb to your computer and use it in GitHub Desktop.
Save getaclue00/d52c4d3c6877738b3478d50613434ffb to your computer and use it in GitHub Desktop.
Checking whether your Mac has an app to open a URL
//
// NSWorkspace+ApplicationForOpeningURL.h
//
// Created by Scott Jackson on 10/07/12.
// Copyright (c) 2012 SJSoftware. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface NSWorkspace (ApplicationForOpeningURL)
/*
Returns a URL of the app that can open `url`. If no app can open `url`, nil is returned.
*/
+ (NSURL *)applicationForOpeningURL:(NSURL *)url;
@end
//
// NSWorkspace+ApplicationForOpeningURL.m
//
// Created by Scott Jackson on 10/07/12.
// Copyright (c) 2012 SJSoftware. All rights reserved.
//
#import "NSWorkspace+ApplicationForOpeningURL.h"
@implementation NSWorkspace (ApplicationForOpeningURL)
+ (NSURL *)applicationForOpeningURL:(NSURL *)url {
FSRef app;
CFURLRef appURL;
LSGetApplicationForURL((CFURLRef)url, kLSRolesAll, &app, &appURL);
if ((NSURL *)appURL)
return (NSURL *)appURL;
return nil;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment