Created
November 23, 2012 21:34
-
-
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.
This file contains 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 characters
# -*- 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