Automator – How to Filter Files by Source

applescriptautomatorfinder

I want to sort my Downloads folder and want to use Automator for it. The Files & Folders library gives me plenty of options, however I was not able to find an action which let me filter files by their source.

I want to sort files by the URL I downloaded them from. Is there an
Automator action I am missing? Or do I have to use Apple Script for
that?

The Filter Finder Files gives me the options for filtering by name, date etc., but not by source. How can I accomplish this task?

Best Answer

Based on your comment, 'I want to say "PDFs downloaded from URL contains "bank name" move to folder "banking"', here is how I'd do it in Automator:

In Automator, create a new Workflow, adding the following Actions:

Find Finder Items, with settings:

  • Search [Downloads]
  • [All] of the following are true
  • [Kind] [is] [PDF]

Run Shell Script, with settings:

  • Shell [/bin/bash]
  • Pass input [as arguments]
  • Replace the default code with the example code below.

    for f in "$@"; do
        [[ $(mdls -name kMDItemWhereFroms "$f") == *bankname* ]] && echo "$f"
    done
    
  • Note: In the code above, replace "bankname" in *bankname* with the actual bank name in the URL.

Move Finder Items, with settings:

  • To [Banking]   [] Replacing existing files
    • Check Replacing existing files if appropriate.