Last active
December 14, 2015 17:59
-
-
Save sergeytimoshin/5126527 to your computer and use it in GitHub Desktop.
Dictionary.app to console output.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* clang -fobjc-arc -framework Foundation -framework CoreServices dict.m -o dict */ | |
#import <Foundation/Foundation.h> | |
#import <CoreServices/CoreServices.h> | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
if(argc < 2) | |
{ | |
printf("Usage: dict <word to define>\n"); | |
return -1; | |
} | |
NSString *search = [NSString stringWithCString: argv[1] encoding: NSUTF8StringEncoding]; | |
CFStringRef def = DCSCopyTextDefinition(NULL, (__bridge CFStringRef)search, CFRangeMake(0, [search length])); | |
NSString * output = [NSString stringWithFormat: @"Definition of <%@>:%@", search, (__bridge NSString *)def]; | |
printf("%s", [output UTF8String]); | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment