Skip to content

Instantly share code, notes, and snippets.

@Fykec
Created November 25, 2013 04:27
Show Gist options
  • Save Fykec/7636366 to your computer and use it in GitHub Desktop.
Save Fykec/7636366 to your computer and use it in GitHub Desktop.
一个小字典脚本,利用了mac程序本身的字典库
#!/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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment