You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Using dictionary from command line

Is it possible I could see the definition of a word for eg. 'Apple' in terminal itself without opening the dictionary app?

I work in the terminal most of the times and I am just wondering if I could get all the information in terminal itself.

Any ideas? Thanks!

Message was edited by: kt.kthapar

iMac 27' Quadcore, Mac OS X (10.6.4)

Posted on Dec 11, 2010 6:04 AM

Reply
Question marked as Top-ranking reply

Posted on Dec 12, 2010 2:56 PM

Linc Davis wrote:
you could install the POSIX 'dict' command (e.g. from MacPorts) which is a client for online dictionaries.


Ugh! How crude!

The suggestion given above launches Dictionary.app, which is apparently not what you want.


Yes indeed. Sorry for not paying more attention.

Since you work in terminal most of the time, a little Xcode can't hurt.
1) Create a new Foundation Command Line Tool in Xcode.
2) Replace the lines:

// insert code here...
NSLog(@"Hello, World!");

with

if(argc < 2)
{
printf("Usage: dict <word to define> ");

return -1;
}

NSString * search =
[NSString stringWithCString: argv[1] encoding: NSUTF8StringEncoding];

CFStringRef def =
DCSCopyTextDefinition(NULL,
(CFStringRef)search,
CFRangeMake(0, [search length]));

NSString * output =
[NSString
stringWithFormat:
@"Definition of <%@>: %@", search, (NSString *)def];

printf("%s", [output UTF8String]);

3) Add the CoreServices framework to the project. Right/command click on "External Frameworks and Libraries", choose "Add..", choose "Existing Frameworks..", choose "CoreServices.framework", and click "Add".
4) Build
5) Enjoy
40 replies

Using dictionary from command line

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.