Skip to content

Instantly share code, notes, and snippets.

@groob
Created July 8, 2017 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groob/3ddf5792899d2cd74114250e98d4751f to your computer and use it in GitHub Desktop.
Save groob/3ddf5792899d2cd74114250e98d4751f to your computer and use it in GitHub Desktop.
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