Created
July 8, 2017 03:29
-
-
Save groob/3ddf5792899d2cd74114250e98d4751f to your computer and use it in GitHub Desktop.
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
package main | |
/* | |
#cgo darwin CFLAGS: -DDARWIN -x objective-c | |
#cgo darwin LDFLAGS: -framework Cocoa | |
#import <Cocoa/Cocoa.h> | |
const char * ReadPlistAndRemoveKey(char *path, char *key) | |
{ | |
NSData *plistData = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%s", path]]; | |
NSError *error; | |
NSPropertyListFormat format; | |
NSMutableDictionary *plist = [NSPropertyListSerialization propertyListWithData:plistData options:NSPropertyListMutableContainers format:&format error:&error]; | |
[plist removeObjectForKey:[NSString stringWithFormat:@"%s", key]]; | |
NSData *data = [NSPropertyListSerialization dataWithPropertyList: plist format:format options: 0 error: &error]; | |
if (data == nil) { | |
const char * cerr = [[NSString stringWithFormat:@"ERROR: %@", error.localizedDescription] UTF8String]; | |
return cerr; | |
} | |
const char * cString = [data bytes]; | |
return cString; | |
} | |
*/ | |
import "C" | |
import ( | |
"fmt" | |
"strings" | |
"unsafe" | |
) | |
func main() { | |
path := "/Applications/Chess.app/Contents/Info.plist" | |
// read plist at path and delete a key. get serialized byte array back. | |
data := C.ReadPlistAndRemoveKey(C.CString(path), C.CString("BuildMachineOSBuild")) | |
defer C.free(unsafe.Pointer(data)) | |
strData := C.GoString(data) | |
fmt.Println(strings.TrimSpace(strData)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment