Jump to content

Allow multiple search prefixes


AlexA

Recommended Posts

It would be great to be able to use multiple search prefixes in Alfred. This can be done right now using a workflow to create a pre-defined set of search prefixes. But there is no way to use an arbitrary combination of search prefixes, which would be extremely useful.

 

For example, suppose you want to search a particular folder for files that contain a particular word. It would be nice to be able to search:

 

f [folder to search] in [search text within files]

 

Or suppose you want to search for a file that you know has a particular tag, etc.:

 

in [search text within files] tags [matching these tags]

 

Again, if you know in advance that there's a specific combination of search prefixes that you intend to use frequently, you can set up a workflow. But that's cumbersome and very different than allowing users the ability to come up with these combinations on the fly. By the way, a great example of this kind of search functionality is in the mail client MailMate. The searching in MailMate is so powerful because you can use multiple search prefixes extremely easily. E.g., this search string looks for all emails from any address that matches "alice", to any other address that matches "bob", with the word "confirmation" in the subject, and containing an attachment with "doc" in the filename:

 

f alice t bob s confirmation A doc

 

Thanks!

Alex

Link to comment
Share on other sites

20 minutes ago, AlexA said:

f [folder to search] in [search text within files]


How does that search a particular folder? Are you supposed to keep typing until your query only matches one folder?

 

I don’t think your suggestion is workable: most of the time you’re going to have multiple matching folders and will need a separate step to select the one you’re actually interested in. Which is basically the way Alfred works now.

 

24 minutes ago, AlexA said:

The searching in MailMate is so powerful because you can use multiple search prefixes extremely easily.


That’s possible because MailMate creates its own search database and knows exactly what it’s put in there.

 

Alfred’s File Filters (or Contacts Filter) could theoretically be made to work in a similar way, but fundamentally, Alfred doesn’t control the data it’s searching the way MailMate does, so making Alfred’s search work as well as MailMate’s is a significantly more difficult task.

Link to comment
Share on other sites

It wouldn't necessarily search a particular folder, but it would search only folders that match the first filter. That would be quite helpful, I think, because it would allow you to more reasonably limit your searches. But setting aside the folder example, the more general suggestion is to have the ability to use multiple search prefixes.

 

In terms of whether it's possible to do this with Alfred, it seems like it should be, right? Alfred can individually parse each of the searches using a prefix, and then return only the results that satisfy all of them. Right? 

 

Of course, I don't know how Alfred actually works underneath the hood, so please forgive any mistaken assumptions.

 

Best,

Alex

 

 

Link to comment
Share on other sites

@AlexA I would suggest taking a look at the Dynamic File Search workflow that's built into Alfred. You'll find it under Workflows > [+] > Examples > Dynamic File Search.

 

Screenshot 2021-03-27 at 08.12.32.png

 

First, you choose a folder within which you'd like to search. Hit enter, then search for content. You could modify this to some extent to suit your needs, in terms of getting the second File Filter to search inside files etc. 

 

By being two steps, it resolves the issue deanishe mentions, in that multiple folders will match what you type in that first stage. With this workflow, I was able to choose my folder by typing two characters and hitting return, rather than having to type the entirety of the folder name.

 

Cheers,
Vero

Link to comment
Share on other sites

15 hours ago, AlexA said:

It wouldn't necessarily search a particular folder, but it would search only folders that match the first filter.

 

Right. I'm not sure how workable that it: there may be 100+ folders, which could absolutely murder performance.

 

15 hours ago, AlexA said:

Alfred can individually parse each of the searches using a prefix, and then return only the results that satisfy all of them. Right?

 

Alfred uses macOS APIs to perform most searches, so it is limited by what those APIs can do.

 

What you're suggesting should be possible for a File Filter to do, but a completely new search mode sounds like something that belongs in a workflow.

Link to comment
Share on other sites

Thanks so much, @Veroand @deanishe, for the suggestions. I’ll give the File Filter a try. Do you know whether it’s possible to do something similar for tags? In other words, a workflow where I can first pick a tag (or even multiple tags?) and then search for files?

 

Also, do you think it would be possible for me (with relatively little scripting experience) to make similar workflows where you can start with a folder filter but then do an “in” search rather than the standard filename search?

 

Really appreciate your help!

Alex

Link to comment
Share on other sites

3 minutes ago, AlexA said:

Do you know whether it’s possible to do something similar for tags? In other words, a workflow where I can first pick a tag (or even multiple tags?) and then search for files?

 

Here is an example. Tweak the list of tags in the List Filter (Title = what's show in Alfred and Arg = the actual tag).

 

The "trick" is saving the selected tag to a variable and putting that in the tag field in the File Filter.

 

12 minutes ago, AlexA said:

Also, do you think it would be possible for me (with relatively little scripting experience) to make similar workflows where you can start with a folder filter but then do an “in” search rather than the standard filename search?

 

Simpler than and very similar to the tags one above. You just need to tweak the Fields settings on the File Filter to search kMDItemTextContent.

 

 

Link to comment
Share on other sites

  • 5 weeks later...

@deanishe and @Vero — I've now successfully set up a work flow to search for a tag and then to search for only files with those tags. I used @deanishe's extremely helpful template to start. What I can't figure out, though, is how to do the same for folders. I tried replicating what @Vero has above, but I can't figure out how to use the JSON utility to set the folder scope for the subsequent file filter search. Any help would be much appreciated, and sorry this is so remedial.

 

Thanks,

Alex

Link to comment
Share on other sites

I'm sure it works, but I'm having a hard time recreating it. Here's what my workflow looks like currently:

 

image.png.190bb4b48c889c4269eaf01d84ccc589.png

 

But I don't know how to configure either the JSON config box or the subsequent File Filter so that the folder I pick in step one is actually used to limit the search in step two. Sorry if this is a really basic question, or if there's some place I should RTFM. Any help much appreciated.

 

Thanks!

Alex

Edited by AlexA
Link to comment
Share on other sites

21 hours ago, AlexA said:

Here's what my workflow looks like currently

 

Pictures don't really help, I'm afraid. Please upload your workflow somewhere (Dropbox?) and post a link, so we can actually see what's going on.

Edited by deanishe
Link to comment
Share on other sites

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