Jump to content
swissmanu

Custom Entries with File Filter

Recommended Posts

Posted (edited)

I use a File Filter to search within files of a specific folder.

In case there is no file found (e.g. no file for query XYZ), I would like to provide a custom entry like "Create XYZ" which then allows me to trigger the creation of a new file using the "XYZ" query string.

The creation of the file is not the problem; I am wondering if this custom entry is possible at all without implementing the file search functionality on my own using a script filter.

Does anyone have an idea how this could be approached using Alfreds built-in features?

 

Thanks :)

Edited by swissmanu

Share this post


Link to post

You could create a Fallback Search that creates a file, and then set that as one of your default fallbacks. Then Alfred will show it whenever there are no results.

 

But there's no way you can tie it to a specific workflow/File Filter. You'd need to use a Script Filter and implement it all yourself.

Share this post


Link to post

hey @deanishe, thank you for your suggestion! i ended up already in my own implementation using a shellscript which uses mdfind internally.

 

in the end i did not check if there are no results, but append a "create" item all the time.

in case somebody wants to do something similar, my code is attached below.

 

cheers :)

 

#!/bin/bash

QUERY=${1}
DIRECTORY="/some/directory"

RESULTS=$(mdfind -onlyin "${DIRECTORY}" "kMDItemContentType == 'net.daringfireball.markdown' && (kMDItemDisplayName == '${QUERY}*'c || kMDItemTextContent == '${QUERY}*'c)")
SAVEIFS=${IFS}
IFS=$'\n'
RESULTS=($RESULTS) # Split Results
IFS=${SAVEIFS}

declare -a ITEMS
for i in "${RESULTS[@]:0:8}"; do
    ITEM=$(cat << EOF
    {
        "uid": "${i}",
        "type": "file",
        "title": "$(echo ${i} | sed 's|.*/||')",
        "subtitle": "${i}",
        "arg": "${i}",
        "icon": {
            "type": "fileicon",
            "path": "${i}"
        }
    },
EOF
    )
    ITEMS+=${ITEM}
done

ITEMS+=$(cat << EOF
    {
        "title": "Create '${QUERY}.md'",
        "subtitle": "Create a new Vault entry",
        "arg": "create:${QUERY}"
    },
EOF
)

cat << EOF
{
    "items": [${ITEMS}]
}
EOF

 

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.

Guest
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...