-
-
Save qunwang6/c85751f07c851229b3c4 to your computer and use it in GitHub Desktop.
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