Created
October 12, 2014 18:11
-
-
Save n8henrie/858b207d8c7c87084e15 to your computer and use it in GitHub Desktop.
Quickly strip email addresses from a block of text with Quicksilver, AppleScript, and Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Regex from http://www.regular-expressions.info/email.html | |
using terms from application "Quicksilver" | |
on get direct types | |
return {"NSStringPboardType"} | |
end get direct types | |
on process text block_text | |
try | |
set python to "import re | |
import sys | |
block_text = sys.argv[1] | |
email_regex = re.compile(r'\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b', re.I) | |
emails = re.findall(email_regex, block_text) | |
print('\\n'.join(emails))" | |
set result to do shell script "python -c \"" & python & "\" " & quoted form of block_text | |
tell application "Quicksilver" to set selection to result | |
on error a number b | |
activate | |
display dialog a with title "error with your QS action script" | |
end try | |
end process text | |
end using terms from |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment