Skip to content

Instantly share code, notes, and snippets.

@n8henrie
Created October 12, 2014 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n8henrie/858b207d8c7c87084e15 to your computer and use it in GitHub Desktop.
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
-- 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