Skip to content

Instantly share code, notes, and snippets.

@JRHeaton
Created December 31, 2013 02:29
Show Gist options
  • Save JRHeaton/8191589 to your computer and use it in GitHub Desktop.
Save JRHeaton/8191589 to your computer and use it in GitHub Desktop.
#include <CoreFoundation/CoreFoundation.h>
void xcselect_trigger_install_request(const char *str) {
CFMutableDictionaryRef options;
CFStringRef toolNameKey, toolName;
CFDataRef optionsData;
options = CFDictionaryCreateMutable(NULL, 0, NULL, NULL);
toolNameKey = CFStringCreateWithCString(NULL, "tool-name", kCFStringEncodingMacRoman);
toolName = CFStringCreateWithCString(NULL, str, kCFStringEncodingMacRoman);
CFDictionarySetValue(options, toolNameKey, toolName);
optionsData = CFPropertyListCreateData(NULL, (CFPropertyListRef)options, kCFPropertyListBinaryFormat_v1_0, 0, NULL);
CFRelease(toolNameKey);
CFRelease(toolName);
CFRelease(options);
if(optionsData) {
CFStringRef portName;
CFMessagePortRef port;
CFDataRef returnData;
portName = CFStringCreateWithCString(NULL, "com.apple.dt.CommandLineTools.installondemand", kCFStringEncodingMacRoman);
port = CFMessagePortCreateRemote(NULL, portName);
if(port) {
CFMessagePortSendRequest(port, 0, optionsData, 0, 0, NULL, &returnData);
}
}
}
int main(int argc, const char **argv) {
const char *name = "clinstall";
if(argc > 1)
name = argv[1];
xcselect_trigger_install_request(name);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment