Created
July 23, 2013 08:59
-
-
Save vbo/6060982 to your computer and use it in GitHub Desktop.
Alfred script filter matching the full file path instead of just filename. See http://apple.stackexchange.com/questions/96701/sublime-text-like-fuzzy-filesystem-search-for-mac-os-x.
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
import os | |
import re | |
print """<?xml version="1.0"?>""" | |
print "<items>" | |
try: | |
query = r"{query}" | |
parts = query.rstrip("/").split("/") | |
filename = parts.pop() | |
regex = r"\/".join((re.escape(part) + ".*" for part in parts)) + r"\/" | |
cmd = "mdfind name:%s | grep -i \"%s\"" %(filename, regex) | |
items = os.popen(cmd).readlines() | |
for item in items: | |
item = item.strip() | |
filename = item.split("/")[-1] | |
print """<item arg="%s" valid="YES" type="file">""" % item | |
print """<title>%s</title>""" % filename | |
print """<subtitle>%s</subtitle>""" % item | |
print """<icon type="fileicon">%s</icon>""" % item | |
print """</item>""" | |
finally: | |
print """<item arg="cmd"><title>%s</title></item>""" % cmd | |
print "</items>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment