alfred_user Posted February 20, 2020 Posted February 20, 2020 I've created a workflow with a File Filter, and set it to only show folder results: Then in the Scope tab I've added one folder: This works, but it produces results from all subfolders of the specified folder. Is there a way to restrict it to only show results from the root folder provided (and not subfolders of that folder)? I found this question from 2015 asking a similar question about the script filter, but there were no good viable solutions.
deanishe Posted February 20, 2020 Posted February 20, 2020 No, it's not possible with a File Filter. They are fundamentally designed to search the whole file tree, as is the Mac metadata index they rely on. You have two options: Tell Alfred to browse the folder with the AppleScript tell application id "com.runningwithcrayons.Alfred" to browse "~/Documents/". This will only the contents of that directory (no subdirectories), but it will show files as well as folders, however. . This will only the contents of that directory (no subdirectories), but it will show files as well as folders, however. Write a workflow with a Script Filter that only shows folders (e.g. using find /path/to/directory -type d -depth 1)
alfred_user Posted February 26, 2020 Author Posted February 26, 2020 @deanishe Thank you! I definitely wanted folders only so I went with the second suggestion. I replaced the File Filter with a Script Filter and this script: find ~/projects ~/internal -maxdepth 1 -name "*$1*" -type d | \ while read line; \ do /usr/local/bin/jq -n \ --arg uid "$(echo \"$line\" | tr -dc '[:alnum:]\n\r' | tr '[:upper:]' '[:lower:]')" \ --arg title "$(basename "$line")" \ --arg subtitle "${line/\/Users\/username/~}" \ '{uid: $uid, title: $title, subtitle: $subtitle}'; \ done | \ /usr/local/bin/jq -n '.items |= [inputs]' It uses jq to build the JSON output that Alfred requires. `jq` needs to be referenced by the full path of the binary, I'm assuming because Alfred does not have access to, or knowledge of, the shell's $PATH variable. One more thing I'd like for this workflow... I want to have each result row show a folder icon. As it is now it just shows the workflow's icon: I read the icon and type sections of the documentation but it's not making sense to me. I tried `"type": "folder"` and also `"icon": { "type": "fileicon" }` but neither seems to have any effect. It appears I could have an icon file loaded from a file but since my results are always going to be folders, is there an fast/native way to just display a folder icon (other than replacing the workflow's icon with a folder icon, since I want that to be different)?
deanishe Posted February 26, 2020 Posted February 26, 2020 (edited) 9 minutes ago, alfred_user said: I'm assuming because Alfred does not have access to, or knowledge of, the shell's $PATH variable. That's right. On macOS, applications aren't launched from your shell (unless you explicitly run one from a shell), so they don't have your shell's environment. 9 minutes ago, alfred_user said: I read the icon and type sections of the documentation but it's not making sense to me. You must specify a value for path. type is optional; path isn't. 9 minutes ago, alfred_user said: is there an fast/native way to just display a folder icon "icon": { "type": "filetype", "path": "public.folder" } Edited February 26, 2020 by deanishe
alfred_user Posted February 26, 2020 Author Posted February 26, 2020 Adding that icon key worked, thanks! I also realized I need the arg key in the object in order to pass the selected path on to the output. Completed script here: find ~/projects ~/internal -maxdepth 1 -name "*$1*" -type d | \ while read line; \ do /usr/local/bin/jq -n \ --arg uid "$(echo \"$line\" | tr -dc '[:alnum:]\n\r' | tr '[:upper:]' '[:lower:]')" \ --arg title "$(basename "$line")" \ --arg subtitle "${line/\/Users\/username/~}" \ --arg arg "$line" \ '{uid: $uid, title: $title, subtitle: $subtitle, arg: $arg, icon: { type: "filetype", path: "public.folder" } }'; \ done | \ /usr/local/bin/jq -n '.items |= [inputs]'
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