├── LaunchSetter.zip ├── README.md ├── ScreenShot1.png └── launchsetter /LaunchSetter.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmhoule/LaunchSetter/129b84f081f5a3a05c9b323eaf5f789fe7195f13/LaunchSetter.zip -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LaunchSetter 2 | Set LaunchServices filetypes 3 | 4 | LaunchSetter is a command line tool to define what program should be used for different URL handlers. For example, what application should open http or mailto links. It should be run as the user account that needs the URL mapped. Do NOT run it as root. If running via a management tool (such as JAMF), you'll need to craete a LaunchAgent to execute the command. 5 | 6 | ![alt text](https://github.com/tmhoule/LaunchSetter/blob/master/ScreenShot1.png) 7 | 8 | # Get Usage: 9 | 10 | LaunchSetter get https 11 | 12 | Will return the application the OS will use for https links. 13 | 14 | # Set Usage: 15 | 16 | LaunchSetter set mailto com.apple.Mail 17 | 18 | Will map mailto links to the application Apple Mail. 19 | 20 | To find the application Bundle ID required by LaunchSetter, type the following in Terminal: 21 | 22 | 23 | defaults read /Applications/Mail.app/Contents/Info.plist CFBundleIdentifier 24 | 25 | # Installing 26 | 27 | Download LaunchSetter from the Repo and copy it somewhere useful like /usr/local/bin. You'll need to make it executable so run the following command. 28 | 29 | chmod +x /path/to/LaunchSetter 30 | 31 | Or you can compile it yourself. 32 | 33 | -------------------------------------------------------------------------------- /ScreenShot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmhoule/LaunchSetter/129b84f081f5a3a05c9b323eaf5f789fe7195f13/ScreenShot1.png -------------------------------------------------------------------------------- /launchsetter: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // LaunchSetter 4 | // 5 | // Created 7/3/17. 6 | // Copyright © 2017 Todd Houle. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, const char * argv[]) { 12 | @autoreleasepool { 13 | if (argc == 1) //if no arguments supplied 14 | { 15 | NSLog(@"Format: LaunchSetter get/set handler program"); 16 | NSLog(@"Example: LaunchSetter set mailto com.microsoft.Outlook"); 17 | exit(0); 18 | } 19 | 20 | 21 | //Get argument 1 is it set or get? 22 | NSString *arg1 = [NSString stringWithUTF8String:argv[1]]; 23 | 24 | if ([arg1 isEqualTo:@"get"]) { 25 | //NSLog(@"Get Found"); 26 | NSString *metaType = [NSString stringWithUTF8String:argv[2]]; 27 | NSString *metaTypeFull = [metaType stringByAppendingString:@"://"]; 28 | CFURLRef mailURL = CFURLCreateWithString(kCFAllocatorDefault, (__bridge CFStringRef)metaTypeFull, NULL); 29 | CFURLRef mailAppURL = NULL; 30 | OSStatus ret = 0; 31 | if((ret = LSGetApplicationForURL(mailURL, kLSRolesAll, NULL, &mailAppURL)) == 0) 32 | { 33 | CFStringRef path = CFURLCopyFileSystemPath(mailAppURL, kCFURLPOSIXPathStyle); 34 | CFShow(path); 35 | 36 | CFRelease(path); 37 | CFRelease(mailAppURL); 38 | } 39 | else 40 | { 41 | fprintf(stderr, "LaunchServices error %d\n", ret); 42 | } 43 | CFRelease(mailURL); 44 | return ret; 45 | 46 | } 47 | 48 | if ([arg1 isEqualToString:@"set"]) 49 | { 50 | //NSLog(@"Set Found"); 51 | if (argc != 4) 52 | { 53 | NSLog(@"Format required: LaunchSetter set handler program"); 54 | NSLog(@"Example: LaunchSetter set mailto com.microsoft.Outlook"); 55 | exit(0); 56 | } 57 | NSString *arg2 = [NSString stringWithUTF8String:argv[2]]; 58 | NSString *arg3 = [NSString stringWithUTF8String:argv[3]]; 59 | 60 | LSSetDefaultHandlerForURLScheme((__bridge CFStringRef _Nonnull)(arg2), (__bridge CFStringRef _Nonnull)(arg3)); 61 | 62 | } 63 | 64 | NSLog(@"Build 436"); 65 | 66 | 67 | 68 | 69 | 70 | } 71 | return 0; 72 | } 73 | --------------------------------------------------------------------------------