swissmanu Posted June 5, 2020 Share Posted June 5, 2020 (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 June 5, 2020 by swissmanu Link to comment
deanishe Posted June 5, 2020 Share Posted June 5, 2020 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. swissmanu 1 Link to comment
swissmanu Posted June 5, 2020 Author Share Posted June 5, 2020 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 pdazero 1 Link to comment
pdazero Posted September 19, 2020 Share Posted September 19, 2020 Hi @swissmanu this works as advertised but it's slower than File Filter (I have several thousand files). Also I've becoming increasingly uncomfortable with scripts like these (checkout the awesome Acidham markdown script) for the same reason, just not snappy on a large note vault. I ended up doing an alternate approach: - Usual File Filter (filename and contents) on my markdown vault - If I want to create a new markdown note, I press a predefined KEY COMBO - This KEY COMBO runs a Keyboard Maestro script that runs copies the original query by means of cmd-a + cmd-c, strips Alfred keyword, creates file and finally opens it The best solution would be to have an option always add custom actions to File Filter (probably to other filters as well). Other workaround would be to store the original query to work with it later with a key modifier action and discard the selected file (if existed) + default callback. But this seems that hasn't been implemented yet, it's on Feature Requests: Thanks, Link to comment
deanishe Posted September 19, 2020 Share Posted September 19, 2020 3 hours ago, pdazero said: just not snappy on a large note vault. That can be mitigated by caching the list of files and updating the cache in the background. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now