Mercurial > my-enso-commands
comparison my-enso-commands.py @ 16:1fee5287e956
Added skype command
| author | Atul Varma <varmaa@toolness.com> |
|---|---|
| date | Sat, 27 Mar 2010 16:12:36 -0700 |
| parents | e96c724d3c7a |
| children | 557f0edc2ca4 |
comparison
equal
deleted
inserted
replaced
| 15:e96c724d3c7a | 16:1fee5287e956 |
|---|---|
| 35 | 35 |
| 36 def cmd_define(ensoapi, word=None): | 36 def cmd_define(ensoapi, word=None): |
| 37 "Look up the given word in the dictionary." | 37 "Look up the given word in the dictionary." |
| 38 | 38 |
| 39 _do_service(ensoapi, "Look Up in Dictionary", word) | 39 _do_service(ensoapi, "Look Up in Dictionary", word) |
| 40 | |
| 41 DEFAULT_COUNTRY_CODE = "1" | |
| 42 DEFAULT_AREA_CODE = "415" | |
| 43 | |
| 44 def number_to_pstn(number, default_country_code=DEFAULT_COUNTRY_CODE, | |
| 45 default_area_code=DEFAULT_AREA_CODE): | |
| 46 """ | |
| 47 Converts a colloquial phone number to a pstn. | |
| 48 | |
| 49 >>> number_to_pstn('123.456.7890', default_country_code='1') | |
| 50 '+11234567890' | |
| 51 | |
| 52 >>> number_to_pstn('456.7890', default_country_code='1', | |
| 53 ... default_area_code='614') | |
| 54 '+16144567890' | |
| 55 | |
| 56 >>> number_to_pstn('5') is None | |
| 57 True | |
| 58 """ | |
| 59 | |
| 60 DIGITS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'] | |
| 61 | |
| 62 chars = "".join([char for char in number if char in DIGITS]) | |
| 63 | |
| 64 if len(chars) == 11: | |
| 65 pass | |
| 66 if len(chars) == 10: | |
| 67 chars = default_country_code + chars | |
| 68 elif len(chars) == 7: | |
| 69 chars = default_country_code + default_area_code + chars | |
| 70 else: | |
| 71 chars = None | |
| 72 | |
| 73 if chars: | |
| 74 return "+%s" % chars | |
| 75 return None | |
| 76 | |
| 77 def cmd_skype(ensoapi, number=None): | |
| 78 "Call the given number with Skype." | |
| 79 | |
| 80 if not number: | |
| 81 number = ensoapi.get_selection().get("text", "").strip() | |
| 82 | |
| 83 if not number: | |
| 84 ensoapi.display_message("No text selection!") | |
| 85 return | |
| 86 | |
| 87 number = number_to_pstn(number) | |
| 88 | |
| 89 if not number: | |
| 90 ensoapi.display_message("That doesn't look like a phone number.") | |
| 91 return | |
| 92 | |
| 93 _runAppleScript('tell application "Skype" ' | |
| 94 'to send command "CALL %s" ' | |
| 95 'script name "Enso"' % number) | |
| 40 | 96 |
| 41 def cmd_speak(ensoapi, what=None): | 97 def cmd_speak(ensoapi, what=None): |
| 42 "Speak the given text out loud." | 98 "Speak the given text out loud." |
| 43 | 99 |
| 44 _do_service(ensoapi, "Speech/Start Speaking Text", what) | 100 _do_service(ensoapi, "Speech/Start Speaking Text", what) |
