Jump to content

Search folder on NAS starting from a predefined folders list

Recommended Posts



I need a workflow that searches folders located on NAS starting from a list of predefined folders. I need also to limit searches to 1 folder depth on NAS for speed and accurate search result.




I want to tell Alfred to look only inside this set of folders:






and limit the folder depth to 1 so only folders inside the folder list are searched.


Using the 'find' command it would be:


find /volumes/data/folder1 -maxdepth 1

find /volumes/data/folder2 -maxdepth 1

find /volumes/data/folder3 -maxdepth 1



NAS is not indexed.


Share this post

Link to post

If it isn't indexed, you'll have to write your own workflow that displays the results of those find calls.

A very basic example (using my Alfred-Workflow library) would look like this:

from __future__ import print_function, unicode_literals

import sys
import hashlib
import subprocess
import argparse

from workflow import Workflow, ICON_WARNING

CACHE_RESULTS_FOR = 10  # seconds

log = None
decode = None

def find(dirpath, query):
    cmd = ['find', dirpath, '-maxdepth', '1', '-name', '*{}*'.format(query)]
    output = decode(subprocess.check_output(cmd))
    return [l.strip() for l in output.split('\n') if l.strip()]

def main(wf):
    parser = argparse.ArgumentParser()
    parser.add_argument('-f', '--folder',
                        help="Search in this folder")
    parser.add_argument('query', help="Search for files with this name")
    args = parser.parse_args(wf.args)

    dirpath = args.folder
    query = args.query

    def wrapper():
        return find(dirpath, query)

    key = '{}::{}'.format(dirpath, query).encode('utf-8')
    m = hashlib.md5()
    key = m.hexdigest()

    results = wf.cached_data(key, wrapper, max_age=CACHE_RESULTS_FOR)

    if not results:
        wf.add_item('No results found', valid=False, icon=ICON_WARNING)

    for path in results:
        wf.add_item(path, valid=True, arg=path, icon=path, icontype='fileicon')


if __name__ == '__main__':
    wf = Workflow()
    log = wf.logger
    decode = wf.decode

Here's a full workflow to get you started. I've created one Script Filter that searches ~/Downloads. You can change that path or duplicate the Script Filter to add other directories.

Edited by deanishe

Share this post

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...