Textexpander with Python to match phone numbers
Question: I want to use Textexpander and Python to match phone numbers via the
clipboard:

  1. Click a phone number formated like `0798008080` in one application, _copy_ the number and insert the clipboard content with a Textexpander-Shortcut in another application like `0041 79 800 80 80`.

  2. Click a phone number formatted like `079 800 80 80` in one application, _copy_ , insert the clipboard content with a Textexpander-Shortcut in another application like `0041 79 800 80 80`.

I have found a Textexpander snippet which sets the clipboard content in
uppercase:

    
    
    #!/usr/bin/python
    import sys
    selection = """%clipboard"""
    sys.stdout.write(selection.upper(), 
    

but I have no clue how to adapt this snippet for my purpose (`%clipboard` is a
code used in Textexpander to access the clipboard content)

Does anyone have a suggestion?


Answer: @hackworks:

Yes I need still help in matching a pattern and transforming it.

I suppose that I need a Python-, Ruby- or perhaps AppleScript-Code for
transforming phone numbers like `0798008080` from the Clipboard (simple copy
the number by ⌘-C on a Mac) to `0041 79 800 80 80` and `079 800 80 80` to
`0041 79 800 80 80`:

  1. ⌘-C (copy) a phone number (`0798008080`) to the clipboard
  2. Go to another application, we say Evernote/Word etc.
  3. Tipping a defined abbreviation from Textexpander like `;phone` which paste the transformed phone number `0041 79 800 80 80` into Evernote/Word etc.

The Python-, Ruby- or AppleScript-Code transforming the phone number is within
the snippet `;phone` from Textexpander:

  1. If I type the shortcut `;phone` (or whatsoever: the shortcuts can be defined by the user itself), Textexpander should get the content from the clipboard (for that, the code `%clipboard` can be used within Textexpander), 
  2. then initiate a
  3. Python-, Ruby- or whatsoever-code transforming the clipboard content (here: phone number),
  4. transfer the transformed clipboard content to Textexpander,
  5. which will (e) replace the shortcut `;phone` (Textexpander) with the transformed phone number and will insert the transformed phone number in Evernote/Word/Excel whatsoever

1, 2, 4 and 5 will be done by Textexpander. The clipboard content
"transforming" Code will be also placed directly in the Textexpander snippet,
in other words, Textexpander will initiate the Python-/Ruby-code.

In the example

    
    
    #!/usr/bin/python
    import sys
    selection = """%clipboard"""
    sys.stdout.write(selection.upper(),
    

Textexpander will do like a similar process: This code is written within a
Textexpander snippet. A shortcut like `;uc` (for uppercase) tipped in Word
will start the Textexpander snippet. Textexpander will get the clipboard
content (%clipboard), push a Python code
(`sys.stdout.write(selection.upper(),`) to uppercase the clipboard content,
and insert the transformed clipboard content in to Word. `#!/usr/bin/python`,
`import sys` and `selection` also have something to do with Python (I suggest
so), but I'am far away from really understand Python.

So, what I need is a Python/Ruby-code for transforming phone numbers formatted
like `0798008080` and `079 800 80 80` to `0041 79 800 80 80` and to put in the
code within Textexpander-workflow.

Does it make sense? Are my remarks understandable enough?

