# HG changeset patch # User Atul Varma # Date 1269731556 25200 # Node ID 1fee5287e9560a8bf67eb203b70f3b1a75e290dd # Parent e96c724d3c7ab1852eb7ba689714cb0f681ea872 Added skype command diff -r e96c724d3c7a -r 1fee5287e956 my-enso-commands.py --- a/my-enso-commands.py Sat Mar 27 15:13:15 2010 -0700 +++ b/my-enso-commands.py Sat Mar 27 16:12:36 2010 -0700 @@ -38,6 +38,62 @@ _do_service(ensoapi, "Look Up in Dictionary", word) +DEFAULT_COUNTRY_CODE = "1" +DEFAULT_AREA_CODE = "415" + +def number_to_pstn(number, default_country_code=DEFAULT_COUNTRY_CODE, + default_area_code=DEFAULT_AREA_CODE): + """ + Converts a colloquial phone number to a pstn. + + >>> number_to_pstn('123.456.7890', default_country_code='1') + '+11234567890' + + >>> number_to_pstn('456.7890', default_country_code='1', + ... default_area_code='614') + '+16144567890' + + >>> number_to_pstn('5') is None + True + """ + + DIGITS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'] + + chars = "".join([char for char in number if char in DIGITS]) + + if len(chars) == 11: + pass + if len(chars) == 10: + chars = default_country_code + chars + elif len(chars) == 7: + chars = default_country_code + default_area_code + chars + else: + chars = None + + if chars: + return "+%s" % chars + return None + +def cmd_skype(ensoapi, number=None): + "Call the given number with Skype." + + if not number: + number = ensoapi.get_selection().get("text", "").strip() + + if not number: + ensoapi.display_message("No text selection!") + return + + number = number_to_pstn(number) + + if not number: + ensoapi.display_message("That doesn't look like a phone number.") + return + + _runAppleScript('tell application "Skype" ' + 'to send command "CALL %s" ' + 'script name "Enso"' % number) + def cmd_speak(ensoapi, what=None): "Speak the given text out loud."