Jump to content
calebaharrison

Dynamic / variables configuration of workflow file filters [Accepted]

Recommended Posts

Hey Folks,

 

Sorry in advance if this isn't the place for V3 workflow tips (and sorry if discussing V3 stuff, here, before public release is poor manners!). I am trying to have the following as a workflow:

  1. Filter file types (e.g. search only PDFs or only .skim notes or only .mmd files)
  2. Search for text within files of that type (e.g. search for 'justice' within only PDFs, or within only .skim notes)
    1. ​(So long as we're talking dream workflow, here, it would also be nice to filter multiply e.g. Search only in [.skim notes] with [tag=Aristotle' AND 'Nussbaum] for [query=justice]...)

I know I can do 'in {query}' to search within files, and I know I can do file filters to search for specific file types, but I don't know how to chain the two so as to search within specific file types. I gather that Alfred V3 should be able to accomplish this (some kind of dynamic file search?), but I'm at a bit of a loss as to how to do it. Would I do a file filter, and pass off the entire result-list of files of that type to the next filter as a JSON utility? Or is this a bit outside the scope of what workflows are supposed to accomplish?

 

Thanks!

Caleb

Edited by calebaharrison

Share this post


Link to post

Hey Folks,

 

 

 

Hi Caleb,

 

Take a look at the Workflows > Examples > Dynamic File Search to get started.

 

In that particular example, typing "ff" then the name of a folder will allow you to dynamically set your search scope to be only the selected folder, you can then type the name of the file you want to find. In theory, there could even be another stage where you select from a List Filter a file type to narrow your search even further.

 

Playing around with that workflow as well as the Simple To-Do list (which also uses multiple variables) will allow you to see how the variables are used dynamically.

 

As you can imagine, there's tons of documentation coming for this, as soon as Alfred 3 goes to general availability, and I expect I'll be doing more tutorials and likely videos too to help users discover these new workflow features :)

 

Have fun and let us know how your workflow creation goes!

 

Cheers,

Vero

Share this post


Link to post

Hi Caleb

 

you can search a specific type of file with a File Filter by setting its file types then under the Advanced tab adding a metadata field for kMDItemTextContent -- this is the Spotlight metadata key for file contents (the default on a File Filter is to search filenames and Finder comments -- you may also want to delete these).

 

In theory (moving on to the dream workflow...) you should be able save file type and tags to a variables, then use a JSON Config to pre-populate the File Filter's type and the search terms for kMDItemUserTags but in practice this doesn't seem to work.  Here's the JSON I'm using:

{
  "alfredworkflow" : {
    "config" : {
      "types" : [
        "{var:fileType}"
      ],
      "fields" : [
        {
          "words" : true,
          "value" : "{var:theTags}",
          "split" : true,
          "not" : false,
          "field" : "kMDItemUserTags"
        },
        {
          "words" : true,
          "value" : "(query)",
          "split" : true,
          "not" : false,
          "field" : "kMDItemTextContent"
        }
      ]
    },
    "variables" : {
    }
  }
}

I've set up a notification to confirm that the variables (fileType and theTags) are set correctly heading into the File Filter, but the File Filter never produces results.  The JSON Config window says it should convert "(query)" to {query} in the File Filter, but maybe this doesn't happen.

 

Vero, any suggestions?

 

Here's the workflow-in-progress.

 

https://dl.dropboxusercontent.com/u/6601556/Alfred/filtered%20search.alfredworkflow

Edited by dfay

Share this post


Link to post

From my tests, it appears that Alfred doesn't expand (query), {query} or {var:…} macros in the "fields" object.

 

A bug?

Share this post


Link to post

Thanks for the suggestions and comments Vero, dfay, and deanishe.

 

dfay, I've been playing around with your workflow, to no avail as well. (Thanks for setting it up and sharing it!) I'll keep playing around. It would be great if this worked, as it would be a super interesting research tool.

Share this post


Link to post

Yep, working now, thanks!

 

Doing the Boolean searches from Caleb's original request is going to be more of a challenge....

Share this post


Link to post
Posted (edited)

Hi dfay,

is the workflow posted on 19 May 2016 working for you or did you make any changes?

 

I tried using it but it didn't work. The filtering on file type is OK (for both branches, with and without tag filtering) but the tag filtering does nothing: when filtering on the content (3rd input) I get files without the selected tag as well.

 

By the way what item shall I add to the list filter to include all file types (i.e. not filtering on types)?

 

Thanks 

Edited by johseb

Share this post


Link to post
On 5/22/2017 at 6:11 AM, johseb said:

 

The filtering on file type is OK (for both branches, with and without tag filtering) but the tag filtering does nothing: when filtering on the content (3rd input) I get files without the selected tag as well.

 

 

Same. My results are not filtered by the tag specified. I tried manually adding a static tag in the file filter (kMDItemUserTags) and it also did not work. I suspect it has something to do with "and/or", but it's over my head.

Share this post


Link to post
Posted (edited)

@Andrew, like @johseb and @evanfuchs, I'm trying to dynamically specify a tag to search using a File Filter object, but it doesn't seem to work with an environment variable. The only dynamic variable that works is {query}... but I would like to set a tag using a variable and then to use the query to filter the list of files. It seems from some post above that this has worked before, but now it doesn't seem to work. I would say this is a bug ? or am I not setting things correctly ?

 

Here is a workflow to show you using {query} as the dynamic field or using a {var:tagTitle} in the File Filter Metadata Field value or by configuring the File Filter using a JSON object. (only the first method with {query} works on my side)

 

https://nofile.io/f/PJs0zmzpFdg/File+Filter+Dynamic+Tag+-+Test.alfredworkflow

 

Using Alfred 3.4.1 Build 860

 

Thanks!

Edited by GuiB

Share this post


Link to post

@GuiB just a quick update on this - I've raised an internal ticket as dynamic configuration of the 'Fields' part of the file filter needs a code update to work (looks like this has never worked). This would get the 'alt' connection path working in your example workflow. It also looks like variable replacement within [complex] config tables also aren't being correctly replaced, so I'll get that sorted too.

 

Your workflow example was completely on point btw, it makes my job significantly easier! :) 

 

Cheers,

Andrew

 

[moving to bugs]

Share this post


Link to post

Great @Andrew ! I'm glad my workflow was helpful! I think I remember having difficulties with some other fields from other objects, so this should be the same thing! Looking forward for the bug fix! :) Thanks again!

Share this post


Link to post

@GuiB This is dealt with by Alfred's workflow framework code, so hopefully fixing arrays / complex arrays for this case will also fix any other areas which weren't working :)

Share this post


Link to post

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
×