Skip to content

Instantly share code, notes, and snippets.

@vbo
Created July 23, 2013 08:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vbo/6060982 to your computer and use it in GitHub Desktop.
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.
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