-
-
Save kuku/d65bdfd779ee54b0ccb01612a623f4c5 to your computer and use it in GitHub Desktop.
Revisions
-
lambdamusic revised this gist
Feb 4, 2016 . 1 changed file with 11 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ #!/usr/bin/env python """ Modified from @@ -21,15 +21,23 @@ import sys try: from DictionaryServices import * except: print "WARNING: The pyobjc Python library was not found. You can install it by typing: 'pip install -U pyobjc'" print "..................\n" try: from colorama import Fore, Back, Style except: print "WARNING: The colorama Python library was not found. You can install it by typing: 'pip install colorama'" print "..................\n" def main(): """ -
lambdamusic revised this gist
Nov 28, 2015 . No changes.There are no files selected for viewing
-
lambdamusic revised this gist
Nov 28, 2015 . No changes.There are no files selected for viewing
-
lambdamusic revised this gist
Nov 28, 2015 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,17 @@ http://macscripter.net/viewtopic.php?id=26675 http://apple.stackexchange.com/questions/90040/look-up-a-word-in-dictionary-app-in-terminal HowTo chmod 755 define.py # make file executable alias define="'/Users/me/Script/define.py'" # => add to .emacs_profile # then (from command line) define recursive # or any other word # .. definition follows .. """ -
lambdamusic revised this gist
Nov 28, 2015 . 2 changed files with 91 additions and 37 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,91 @@ #!/usr/bin/python """ Modified from http://macscripter.net/viewtopic.php?id=26675 http://apple.stackexchange.com/questions/90040/look-up-a-word-in-dictionary-app-in-terminal """ import sys from DictionaryServices import * try: from colorama import Fore, Back, Style except: print "WARNING: The colorama Python library was not found. You can install it by typing: 'pip install colorama'" print "..................\n" def main(): """ define.py Access the default OSX dictionary 2015-11-27 -added colors via colorama """ 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: s = dictresult.encode("utf-8") arrow = doColor("\n\n\xe2\x96\xb6 ", "red") s = s.replace('\xe2\x96\xb6', arrow) # arrow bullet = doColor("\n\xe2\x80\xa2 ", "red") s = s.replace('\xe2\x80\xa2', bullet) # bullet phrases_header = doColor("\n\nPHRASES\n", "important") s = s.replace('PHRASES', phrases_header) derivatives_header = doColor("\n\nDERIVATIVES\n", "important") s = s.replace('DERIVATIVES', derivatives_header) origin_header = doColor("\n\nORIGIN\n", "important") s = s.replace('ORIGIN', origin_header) print doColor("Dictionary entry for:\n", "red") print s print "\n---------------------------------" def doColor(s, style=None): """ util for returning a colored string if colorama is not installed, FAIL SILENTLY """ try: if style == "comment": s = Style.DIM + s + Style.RESET_ALL elif style == "important": s = Style.BRIGHT + s + Style.RESET_ALL elif style == "normal": s = Style.RESET_ALL + s + Style.RESET_ALL elif style == "red": s = Fore.RED + s + Style.RESET_ALL elif style == "green": s = Fore.GREEN + s + Style.RESET_ALL except: pass return s if __name__ == '__main__': main() This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,37 +0,0 @@ -
lambdamusic revised this gist
Nov 12, 2015 . 1 changed file with 23 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,9 @@ #!/usr/bin/python """ Modified from http://macscripter.net/viewtopic.php?id=26675 http://apple.stackexchange.com/questions/90040/look-up-a-word-in-dictionary-app-in-terminal """ @@ -10,19 +13,25 @@ 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: s = dictresult.encode("utf-8") s = s.replace('\xe2\x96\xb6', "\n\n\xe2\x96\xb6 ") # arrow s = s.replace('\xe2\x80\xa2', "\n\xe2\x80\xa2 ") # bullet s = s.replace('PHRASES', "\n\nPHRASES\n") s = s.replace('DERIVATIVES', "\n\nDERIVATIVES\n") s = s.replace('ORIGIN', "\n\nORIGIN\n") print s if __name__ == '__main__': main() -
lambdamusic created this gist
Nov 12, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ #!/usr/bin/python """ http://macscripter.net/viewtopic.php?id=26675 http://apple.stackexchange.com/questions/90040/look-up-a-word-in-dictionary-app-in-terminal """ 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()