mareoraft Posted December 13, 2013 Share Posted December 13, 2013 Can I apply regular expressions to a query before passing it on? For example, instead of "tel:{query}" I want to do something more like "tel:{query} s/\(([0-9]{3})\) ([0-9]{3})-([0-9]{4})/\1\2\3" which would effectively strip the telephone number of its parenthesis and dash. Thanks! (P.S., if not possible directly in URI/URL scheme, how to do it with Applescript or Javascript or Ruby or some language?) (P.P.S. in Alfred it says "URL scheme" but elsewhere I see "URI scheme" online) Link to comment
jdfwarrior Posted December 13, 2013 Share Posted December 13, 2013 Can I apply regular expressions to a query before passing it on? For example, instead of "tel:{query}" I want to do something more like "tel:{query} s/\(([0-9]{3})\) ([0-9]{3})-([0-9]{4})/\1\2\3" which would effectively strip the telephone number of its parenthesis and dash. Thanks! (P.S., if not possible directly in URI/URL scheme, how to do it with Applescript or Javascript or Ruby or some language?) (P.P.S. in Alfred it says "URL scheme" but elsewhere I see "URI scheme" online) Anything you can do in terminal, or via script can be done in Alfred, so yes. You may have to pass it through a script first, but most of it is usually possible one way or another Link to comment
Tyler Eich Posted December 13, 2013 Share Posted December 13, 2013 Alfred will not handle regular expressions for you. However, you can easily accomplish this using a script. In Python, to remove all non-numeric characters (using regular expressions): import re formatted = re.sub(r'[^\d]+', '', '{query}') Code originally from Stack Overflow Link to comment
mareoraft Posted December 14, 2013 Author Share Posted December 14, 2013 Thanks this is what I was looking for!!! Okay so now my python script says import re import os formatted = re.sub(r'[^\d]+', '', '{query}') os.system("open tel:"+formatted) and it works. Thanks for the help. Link to comment
mareoraft Posted December 14, 2013 Author Share Posted December 14, 2013 And here is an equivalent script using Perl. $phonenum = "{query}"; $phonenum =~ s/[- )(+]//g; system("open tel:$phonenum"); awesome! yay! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now