Forked from scottjacksonx/NSWorkspace+ApplicationForOpeningURL.h
Created
August 19, 2018 16:37
-
-
Save getaclue00/d52c4d3c6877738b3478d50613434ffb to your computer and use it in GitHub Desktop.
Checking whether your Mac has an app to open a URL
This file contains 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 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