In my Mac application, I need to write the file to \ Library \ ColorSync \ Profiles. For this, the application needs administrator privileges to read the write to the folder. Is it possible to get the same in the application? Any help would be appreciated.
I can open the dialog with the following code snippet
NSSavePanel *tvarNSSavePanelObj = [NSSavePanel savePanel]; [tvarNSSavePanelObj setDirectoryURL:[NSURL URLWithString:@"/Library/ColorSync/Profiles"]]; __block NSString *filePathexn = nil; [tvarNSSavePanelObj beginSheetModalForWindow:[NSApplication sharedApplication].mainWindow completionHandler:^(NSInteger tvarInt) { if(tvarInt == NSModalResponseOK){ NSURL* tvarUrl = [tvarNSSavePanelObj URL]; NSLog(@"doSaveAs filename = %@",[tvarUrl path]); NSString *filePath = [tvarUrl path]; filePathexn = [filePath stringByAppendingPathExtension:@"rtf"]; OSStatus status; if(![[NSFileManager defaultManager]isWritableFileAtPath:filePath]){ NSLog(@"Not Writable at path"); AuthorizationRef authRef; AuthorizationItem right = {kAuthorizationRightExecute, 0, NULL, 0}; AuthorizationRights rights = {1, &right}; status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagPreAuthorize, &authRef); AuthorizationFlags authFlags = kAuthorizationFlagDefaults | kAuthorizationFlagExtendRights | kAuthorizationFlagInteractionAllowed | kAuthorizationFlagPreAuthorize; status = AuthorizationCopyRights(authRef, &rights, kAuthorizationEmptyEnvironment, authFlags, NULL); } BOOL status1 = [[NSFileManager defaultManager]createFileAtPath:filePathexn contents:nil attributes:nil]; } else if(tvarInt == NSModalResponseCancel) { return; } else { NSLog(@"doSave As tvarInt not equal 1 or zero = %3ld",(long)tvarInt); return; } }];
I need to know how to write a file. The file is not written to the path. Is any tool name required? Will it be possible with SMJobless ()? Please advise a solution!
objective-c file-permissions macos
iGo
source share