Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
OSX dictionary definition lookup
// Command-line dictionary lookup.
//
// Build with:
// clang -framework CoreServices
// clang -fobjc-arc -fmodules definition.m -o definition
#import <CoreFoundation/CoreFoundation.h>
#import <CoreServices/CoreServices.h>
int main(int argc, char *argv[]) {
if (argc < 2)
return 1;
for (int i = 1; i < argc; i++) {
CFStringRef searchPhrase = CFStringCreateWithCString(NULL, argv[i], kCFStringEncodingUTF8);
if (searchPhrase) {
CFRange searchRange = DCSGetTermRangeInString(NULL, searchPhrase, 0);
CFStringRef definition = DCSCopyTextDefinition(NULL, searchPhrase, searchRange);
if (definition) {
printf("--- definition of %s:\n", argv[i]);
} else {
printf("--- no definition found for %s\n\n", argv[i]);
}
CFShow(definition);
CFRelease(definition);
}
CFRelease(searchPhrase);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.