Skip to content

Instantly share code, notes, and snippets.

@NSExceptional
Last active December 23, 2015 10:25
Show Gist options
  • Save NSExceptional/40034f738ede723f2621 to your computer and use it in GitHub Desktop.
Save NSExceptional/40034f738ede723f2621 to your computer and use it in GitHub Desktop.
A program that adds the UUID of the current installation of Xcode (in /Applications/Xcode.app) to every Xcode plug-in's Info.plist. Does nothing if the plug-in already contains the current UUID.
//
// main.m
// UpdateXcodePluginUUIDs
//
// Created by Tanner on 12/21/15.
// Copyright © 2015 Tanner Bennett. All rights reserved.
//
#import <Foundation/Foundation.h>
NSString * const kMessage = @"\nUsage: updateudids [udid]\n";
NSString * const kPluginPath = @"/Library/Application Support/Developer/Shared/Xcode/Plug-ins/";
NSArray * RXArgsFromCharPtr(const char **vargs, int c);
NSString * PUGetLatestUUID();
int main(int argc, const char * argv[]) {
@autoreleasepool {
if (argc != 1) {
printf("%s", kMessage.UTF8String);
return 0;
}
// Get UUID and plugin path
NSString *uuid = PUGetLatestUUID(); uuid = [uuid substringToIndex:uuid.length-1];
NSString *path = [NSHomeDirectory() stringByAppendingString:kPluginPath];
// Get all plugin names
NSArray *plugins = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];
plugins = [plugins filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self ENDSWITH '.xcplugin'"]];
// Change "Foo.xcplugin" to "~/Library/.../Foo.xcplugin/Contents/Info.plist"
plugins = ({
NSMutableArray *fullPathsToInfoPLIST = [NSMutableArray new];
for (NSString *plugin in plugins)
[fullPathsToInfoPLIST addObject:[NSString stringWithFormat:@"%@%@/Contents/Info.plist", path, plugin]];
fullPathsToInfoPLIST;
});
// Open PLIST, add UUID, write it to the file
for (NSString *info in plugins) {
NSMutableDictionary *plist = [NSDictionary dictionaryWithContentsOfFile:info].mutableCopy;
if (!plist) continue;
NSMutableSet *uuids = [NSSet setWithArray:plist[@"DVTPlugInCompatibilityUUIDs"]].mutableCopy;
[uuids addObject:uuid];
plist[@"DVTPlugInCompatibilityUUIDs"] = uuids.allObjects;
[plist writeToFile:info atomically:YES];
}
}
return 0;
}
NSString * PUGetLatestUUID() {
NSTask *task = [NSTask new];
task.launchPath = @"/bin/sh";
task.arguments = @[@"-c", @"defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilityUUID"];
NSPipe *pipe = [NSPipe pipe];
task.standardOutput = pipe;
[task launch];
return [[NSString alloc] initWithData:[pipe.fileHandleForReading readDataToEndOfFile] encoding:NSUTF8StringEncoding];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment