Skip to content

Instantly share code, notes, and snippets.

@mh61503891
Created November 23, 2012 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mh61503891/4137411 to your computer and use it in GitHub Desktop.
Save mh61503891/4137411 to your computer and use it in GitHub Desktop.
Sublime Text 2's plugin that looks up a word beside a caret or a selected text in Dictionary.app.
# -*- coding: utf-8; -*-
#
# Author :: Masayuki Higashino
#
# This plugin looks up a word beside a caret or a selected text in
# Dictionary.app without changing activeness of Sublime Text 2.app's window.
#
# In order to use this plugin, Add a keymap such as a follow into user's key bindings.
# { "keys": ["super+d"], "command": "look_up_in_dictionary" }
import sublime, sublime_plugin, os, urllib
class LookUpInDictionaryCommand(sublime_plugin.TextCommand):
def run(self, edit):
region = self.view.sel()[0]
if region.empty():
s = self.view.substr(self.view.word(region.a))
else:
s = self.view.substr(region)
os.system('open -g dict://' + urllib.quote(s.encode('utf-8')) + ' &')
os.system('say "' + s.encode('utf-8') + '" &')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment