Created
January 9, 2018 12:34
-
-
Save dautermann/119ca5bb0c851c88ea0289b94cb79be3 to your computer and use it in GitHub Desktop.
create desktop alias to current macOS app
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
#import <Cocoa/Cocoa.h> | |
@interface AddAliasToDesktopUtility : NSObject { | |
} | |
- (BOOL) addAliasNow; | |
@end | |
@implementation AddAliasToDesktopUtility | |
- (BOOL) addAliasNow | |
{ | |
NSArray *arr = [[NSFileManager defaultManager] URLsForDirectory: NSDesktopDirectory inDomains: NSUserDomainMask]; | |
NSURL *desktopUrl = [arr firstObject]; | |
NSURL *originalUrl = [[NSBundle mainBundle] bundleURL]; | |
NSURL *aliasUrl = [desktopUrl URLByAppendingPathComponent:[originalUrl lastPathComponent]]; | |
NSData *bookmarkData = [originalUrl bookmarkDataWithOptions: NSURLBookmarkCreationSuitableForBookmarkFile includingResourceValuesForKeys:nil relativeToURL:nil error:NULL]; | |
NSError *err; | |
if(bookmarkData != nil) { | |
BOOL success = [NSURL writeBookmarkData:bookmarkData toURL:aliasUrl options:NSURLBookmarkCreationSuitableForBookmarkFile error:&err]; | |
if(NO == success) { | |
//error | |
NSLog(@"error is %@", [err localizedDescription]); | |
return FALSE; | |
} | |
} | |
return TRUE; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment