Skip to content

Instantly share code, notes, and snippets.

@jtdreisb
Created February 13, 2012 00:20
Show Gist options
  • Save jtdreisb/1812018 to your computer and use it in GitHub Desktop.
Save jtdreisb/1812018 to your computer and use it in GitHub Desktop.
utility that syncs an arbitrary bundle id's prefs
CC = clang
CFLAGS = -Wall -g
LDFLAGS = -framework CoreFoundation
TARG = syncdefaults
SRC=\v
syncdefaults.c\
HFILES=\
OBJS= $(patsubst %.c, %.o, $(SRC))
all: $(TARG)
clean:
rm -f $(OBJS) *~
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
$(TARG): $(OBJS) $(HFILES)
$(CC) $(LDFLAGS) -o $(TARG) $(OBJS)
#include <stdlib.h>
#include <stdio.h>
#include <CoreFoundation/CoreFoundation.h>
//#include <CoreFoundation/CFPreferences.h>
void
usage ( void ) {
printf("usage : syncdefaults <bundle domain>");
exit(1);
}
int
main(int argc, char ** argv) {
if (argc == 2) {
CFStringRef bundleDomain = CFStringCreateWithCString(kCFAllocatorDefault, argv[1], kCFStringEncodingUTF8);
if ( CFPreferencesSynchronize(bundleDomain, kCFPreferencesAnyUser, kCFPreferencesCurrentHost ) == false) {
printf("Failed to write userdefaults for %s\n", argv[1]);
exit(1);
}
} else {
usage();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment