Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Is there a bash or applescript to look up a word in /Applications/Dictionary.app from a Terminal window ?

open -a /Applications/Dictionary.app/ --args word

ignores --args, says "type a word to look up"

Mac Dictionary improvements suggests ⌃ Control ⌘ Command D however I'm looking to launch the full app, not just the small popover.

share|improve this question
    
Instead of the "more" button you just click the dictionary's name in the pop-up to open the search in the dictionary application. –  gentmatt Apr 29 '13 at 10:58
    
Thanks everybody, there's_more_than_one_way_to_skin_a_cat –  denis Apr 29 '13 at 12:29

3 Answers 3

up vote 8 down vote accepted

You can use...

open dict://my_word

...which will open the Dictionary application and lookup the string my_word. If you want to use multiple words use something like open dict://"Big Bang Theory".

There's no output in the Terminal though.

share|improve this answer
    
Thanks. Is there a list of open magicprefix:... someplace ? –  denis Apr 29 '13 at 11:16
    
@Denis I don't know of a source that specifically collects undocumented command options for open. But generally speaking, hints.macworld.com is a well known source for hidden gems. I also used to know a different source which collects undocumented defaults write commands, but I can't remember it just know and Google did not help me either... –  gentmatt Apr 29 '13 at 11:37
    
I made a brief summary of open on SuperUser a while ago superuser.com/questions/4368/os-x-equivalent-of-windows-run-box/… –  David Pearce Apr 30 '13 at 12:16
    
@denis the system maintains a database of all the prefixes that all the apps installed have told it how to handle. If you can think of a practical use for knowing that tidbit, asking a full question would be awesome. –  bmike May 5 '13 at 14:12

Using the Python Objective-C bindings, you could create just a small python script to get it from the built in OS X Dictionary. Here's a post that details this script"

#!/usr/bin/python

import sys
from DictionaryServices import *

def main():
    try:
        searchword = sys.argv[1].decode('utf-8')
    except IndexError:
        errmsg = 'You did not enter any terms to look up in the Dictionary.'
        print errmsg
        sys.exit()
    wordrange = (0, len(searchword))
    dictresult = DCSCopyTextDefinition(None, searchword, wordrange)
    if not dictresult:
        errmsg = "'%s' not found in Dictionary." % (searchword)
        print errmsg.encode('utf-8')
    else:
        print dictresult.encode('utf-8')

if __name__ == '__main__':
    main()

Save that to dict.py, and then just run python dict.py dictation

enter image description here

Check out the post for more instructions on making it accessable all across your terminal.

share|improve this answer

I was also going to suggest open dict://word, but Google's dictionary API also uses the New Oxford American Dictionary:

#!/usr/bin/env ruby

require "open-uri"
require "json"
require "cgi"

ARGV.each { |word|
  response = open("http://www.google.com/dictionary/json?callback=dict_api.callbacks.id100&q=#{CGI.escape(word)}&sl=en&tl=en&restrict=pr,de").read
  results = JSON.parse(response.sub(/dict_api.callbacks.id100\(/, "").sub(/,200,null\)$/, ""))
  next unless results["primaries"]
  results["primaries"][0]["entries"].select { |e| e["type"] == "meaning" }.each { |entry|
    puts word + ": " + entry["terms"][0]["text"].gsub(/x3c\/?(em|i|b)x3e/, "").gsub("x27", "'")
  }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.