Jump to content

Help with easy python workflow


Recommended Posts

So this is my first time working with python and alfred scripts. So please bear with me.

 

I was using deanishe's guide on creating a python script - but having some issues with the python script

import sys
import phonenumbers
import geocoded
x = "'{query}'" # input needs to be wrapped in quotes-is this called correctly?
z = phonenumbers.parse(x, "US")
phonenumbers.format_number(z, phonenumbers.PhoneNumberFormat.NATIONAL)

# How do I return result into alfred?

I'm using Googles Python Library phonenumbers

https://github.com/daviddrysdale/python-phonenumbers

 

 

 

Link to comment

Which "deanishe's guide" are you following?
 
AFAIK, the only one I wrote assumes the use of the Alfred-Workflow library (which helps you send the results to Alfred).
 
Also, you almost certainly don't want the two sets of quotes in x = "'{query}'".

x = "{query}" is enough.

Link to comment
# How do I return result into alfred?

 

This question also has multiple answers based on how you're setting up the workflow. If you want to use a Script Filter to show the results instantly, then you really should use Dean's Alfred-Workflow library because it makes generating Alfred XML feedback much, much simpler. Otherwise, you need to generate the XML yourself.

 

If you are just running a keyword -> script action -> copy to clipboard / show notification / large text, then you just need to print a string in the script, and that printed output will be passed to the next item in the workflow as `{query}`.

Link to comment

I've written a fairly basic example workflow using the python-phonenumbers library. It should do what you want it to if I've discerned your intentions correctly. You can download it here.
 
I'd encourage you to study the code in the tel.py file (what the Script Filter runs), which is fairly heavily commented to explain what's going on, and the Alfred-Workflow tutorial (and other docs) to follow what's going on "behind the scenes".

 

Perhaps you can think of a way to improve the workflow to make it useful to other people (e.g. displaying several different formats and/or understanding phone numbers that aren't from the US).

 

Feel free to ask if you have any more questions about it, or to click on the "Buy me a beer" link below ;)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...