Monday, August 3, 2020
  • Index
  •  » Code Exchange
  •  » Access content in Leopard's Dictionary.app from the command line

#1 2008-08-12 06:01:23 am

Martin Michel
Administrator
From:: Berlin, Germany
Registered: 2008-03-03
Posts: 701
Website

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:

[code]chmod 755 /Users/martin/Downloads/dict.py[/code]
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 smile

[code]alias dict="'/Users/martin/Library/Script/My Scripts/dict.py'"[/code]
Finished!

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

[code]dict 'Steve Wozniak'[/code]
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!


Plonum - Convert images to iWork Numbers documents

Offline

 
  • Index
  •  » Code Exchange
  •  » Access content in Leopard's Dictionary.app from the command line

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)