Skip to content

Instantly share code, notes, and snippets.

@Daij-Djan
Created April 8, 2014 12:40
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 Daij-Djan/10118100 to your computer and use it in GitHub Desktop.
Save Daij-Djan/10118100 to your computer and use it in GitHub Desktop.
plutilIdent: tiny quick&dirty (very) utility that checks if two given plists/strings files contain equal keys
//
// main.m
// plutilIdent
//
// Created by Dominik Pich on 08/04/14.
// Copyright (c) 2014 Dominik Pich. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
if(argc!=3) {
NSLog(@"missing args: plist1 plist2");
return -1;
}
//read plist1
NSDictionary *plist1;
@try {
id path = [@(argv[1]) stringByExpandingTildeInPath];
plist1 = [NSDictionary dictionaryWithContentsOfFile:path];
if(!plist1) {
NSLog(@"Cant open %@", path);
return -1;
}
}
@catch (NSException *exception) {
NSLog(@"Failed to parse plist1");
return -1;
}
//read plist2
NSDictionary *plist2;
@try {
id path = [@(argv[2]) stringByExpandingTildeInPath];
plist2 = [NSDictionary dictionaryWithContentsOfFile:path];
if(!plist2) {
NSLog(@"Cant open %@", path);
return -1;
}
}
@catch (NSException *exception) {
NSLog(@"Failed to parse plist2");
return -1;
}
//check 1>2
for (NSString *key in plist1.allKeys) {
if(![plist2 objectForKey:key]) {
NSLog(@"not in plist2: %@", key);
}
}
//check 2>1
for (NSString *key in plist2.allKeys) {
if(![plist1 objectForKey:key]) {
NSLog(@"not in plist1: %@", key);
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment