Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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
Add Comment
Please, Sign In to add comment