Access content in Leopard's Dictionary.app from the command line

Yesterday I found a way to access content in Leopard’s Dictionary.app with AppleScript by using a tiny Python helper script. The Python script relies on PyObjC, which is preinstalled on Mac OS X 10.5 and allows to take advantage of the newly introduced Dictionary Services.

But you can also use my small script to conveniently look-up terms in the Dictionary from the Terminal. First download «dict.py» to your computer. Then make it executable with chmod. Open a Terminal window and enter the following command. Of course you will have to change the file path according to your own environment:

chmod 755 /Users/martin/Downloads/dict.py

After making it executable, you can save the script file to the folder of your choice. Mine is «/Users/martin/Library/Script/My Scripts/dict.py».

Once again open a Terminal window and type the following command. Yes, you will have to adjust the quoted path to your own location :slight_smile:

alias dict="'/Users/martin/Library/Script/My Scripts/dict.py'"

Finished!

Now you can type the following command in the open Terminal window:

dict 'Steve Wozniak'

Wohoooo!

But unfortunately this is not yet a permanent solution. The moment you close the Terminal window, your command alias is lost. Therefor it is even better if you create a hidden text file named «.bash_profile» in your home folder where you simply enter the above mentioned alias command. In case the file already exists, you can add the command to the existing lines. I did this with the free text editor TextWrangler. Then Terminal.app will remember your dict command in the future.

Happy Scripting!