-
Notifications
You must be signed in to change notification settings - Fork 1
/
launchsetter
72 lines (56 loc) · 2.19 KB
/
launchsetter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// main.m
// LaunchSetter
//
// Created 7/3/17.
// Copyright © 2017 Todd Houle.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
if (argc == 1) //if no arguments supplied
{
NSLog(@"Format: LaunchSetter get/set handler program");
NSLog(@"Example: LaunchSetter set mailto com.microsoft.Outlook");
exit(0);
}
//Get argument 1 is it set or get?
NSString *arg1 = [NSString stringWithUTF8String:argv[1]];
if ([arg1 isEqualTo:@"get"]) {
//NSLog(@"Get Found");
NSString *metaType = [NSString stringWithUTF8String:argv[2]];
NSString *metaTypeFull = [metaType stringByAppendingString:@"://"];
CFURLRef mailURL = CFURLCreateWithString(kCFAllocatorDefault, (__bridge CFStringRef)metaTypeFull, NULL);
CFURLRef mailAppURL = NULL;
OSStatus ret = 0;
if((ret = LSGetApplicationForURL(mailURL, kLSRolesAll, NULL, &mailAppURL)) == 0)
{
CFStringRef path = CFURLCopyFileSystemPath(mailAppURL, kCFURLPOSIXPathStyle);
CFShow(path);
CFRelease(path);
CFRelease(mailAppURL);
}
else
{
fprintf(stderr, "LaunchServices error %d\n", ret);
}
CFRelease(mailURL);
return ret;
}
if ([arg1 isEqualToString:@"set"])
{
//NSLog(@"Set Found");
if (argc != 4)
{
NSLog(@"Format required: LaunchSetter set handler program");
NSLog(@"Example: LaunchSetter set mailto com.microsoft.Outlook");
exit(0);
}
NSString *arg2 = [NSString stringWithUTF8String:argv[2]];
NSString *arg3 = [NSString stringWithUTF8String:argv[3]];
LSSetDefaultHandlerForURLScheme((__bridge CFStringRef _Nonnull)(arg2), (__bridge CFStringRef _Nonnull)(arg3));
}
NSLog(@"Build 436");
}
return 0;
}