Created
July 10, 2012 05:58
-
-
Save scottjacksonx/3081446 to your computer and use it in GitHub Desktop.
Checking whether your Mac has an app to open a URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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