Jump to content

File/Folder search Script Filters

Recommended Posts

So one of my peeves with Alfred and one of the edges I felt Quicksilver held against it was the ability to index just a folder, recursively to a defined level, and search those results.  I keep all my media out on a NAS and having spotlight index those volumes just doesn't bode well for any of the involved parties, so I could never use Alfred quite like I could Quicksilver for quickly finding a TV show or Movie out on my file server.  Thanks to script filters and some of jdfwarrior's great scripting hints, that's no longer true:


$utils = new ExtensionUtils();

$query = urlencode( "{query}" );
$results = array();

$pattern = "/$query/i";

$dir = "/Volumes/video/movies";

if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
	        if ($file != "." && $file != ".."  && ($query && preg_match($pattern, $file))) {

				switch(pathinfo("$dir/$file", PATHINFO_EXTENSION)):
					case 'mkv': $icon = 'MKV.png'; break;
					case 'avi': $icon = 'AVI.png'; break;
					case 'm4v': 
					case 'mp4': $icon = 'M4V.png'; break;
					default: $icon = 'movie.png'; break;

				$item = array(
					'uid' => 'show',
					'arg' => "$dir/$file",
					'title' => $file,
					'subtitle' => "$dir/$file",
					'icon' => $icon,
					'valid' => 'true'
				array_push( $results, $item );

echo $utils->arrayToXml( $results );




There's no good way (yet) to make this easily configurable, so posting it out as a full workflow for download seems a bit silly at this point, but perhaps this code might help somebody along the way achieve what they need.

Link to comment
  • 1 month later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...