3

I've been trying to make an Automator droplet that removes files of a particular extension from a directory. My Workflow has 3 actions (when I'm not debugging):

  1. Get Folder Contents (Repeating for each subfolder)
  2. Filter Finder Items (File extension is "part")
  3. Move Finder Items to Trash

It's #2 that seems to be giving me problems. No matter what I do, no files ever pass through its filter. When I expand the results for Get Folder Contents and any other Finder actions, I always see files in the results. But even when I specify the most permissive filters, this action never produces anything.

If you want to debug this, just insert a new action up top: Get Specified Finder Items, dropping on any directory that has any files within it - although technically the "Filter Finder Items" should also be able to return folders.

Update

I'm now on Lion, and seeing the exact same behavior. I also tried replacing step 2's criteria with "Name ends with 'part'" but that didn't make a difference either. I ultimately ended up writing an AppleScript that accomplished the same task (see below).

9
  • Cannot reproduce. Both "py" (Python source code) and "trec" (not known to the system) work. Get Specified Finder Items -> Get Folder Contents -> Filter Finder Items.
    – Daniel Beck
    Nov 5, 2010 at 9:08
  • You could try running the Mac OS X combo updater for your current version again. Sounds like there might be an issue with older/incompatible Automator actions. Have you upgraded from a previous Mac OS X version?
    – Daniel Beck
    Nov 5, 2010 at 9:09
  • Yeah, I upgraded way back when Snow Leopard first came out, and I've kept up to date.... How would I repair Automator? Copy from another system?
    – Dov
    Nov 5, 2010 at 10:50
  • I also just reproduced this on my other Snow Leopard machine in the house with the same file.
    – Dov
    Nov 6, 2010 at 11:11
  • Can you reproduce with arbitrary file extensions? Is "part" the real file extension, or is it maybe in the form ".part.xxx" with ".xxx" hidden in Finder?
    – Daniel Beck
    Nov 6, 2010 at 16:23

5 Answers 5

2

check your spotlight privacy preferences. If the folder you are working with is not being indexed by spotlight, then the filter command will find nothing.

2
  • Could be the rub. I couldn’t reproduce the bug when testing, but I tested inside my home folder (i.e. in an indexed area).
    – kopischke
    Nov 10, 2011 at 10:49
  • 1
    That was definitely the piece of missing information. That never even occurred to me. I have to wonder, though, why there isn't a way to filter a selection that isn't Spotlight-indexed.
    – Dov
    Nov 18, 2011 at 16:12
0

It seems newly added files to a folder (as in earlier in the workflow) seem to be missing from the results. For example, see my attached image of my workflow (the first is just a get folder contents).

enter image description here

1
  • 1
    So, what are you suggesting? I just tried setting the Filter Finder Items criteria to "Name ends with .part", analogous to your example, but still, no files come through. Also, I'm on Lion now.
    – Dov
    Sep 30, 2011 at 12:27
0

I wrote an AppleScript to accomplish the same task, but I won't accept this answer, since I still think something's wrong with Automator (or I'm not understanding something fundamental about it). This is the AppleScript for a droplet that accepts one or more folders and removes all files ending with .part and has been working flawlessly for months, now (on Snow Leopard and Lion).

on open theItems

    repeat with theItem in theItems
        set theInfo to info for theItem

        --Verify dropped items are folders
        if not folder of theInfo then
            my warnUser(theInfo's name)
        else
            --Empty out the .part files
            my removePartFiles(theItem)
        end if
    end repeat
end open

on run
    my warnUser(missing value)
    -- Used for debugging
    --my removePartFiles("Macintosh HD:Users:Username:Some Test Folder:" as alias)
end run

-- Calls itself recursively
on removePartFiles(RootDirectory)
    tell application "Finder"
        delete (every file of RootDirectory whose name ends with ".part")

        set subFolders to folders of RootDirectory
        repeat with eachFolder in subFolders
            my removePartFiles(eachFolder)
        end repeat
    end tell
end removePartFiles

on warnUser(itemName)
    set msg to "Please drop folder(s) onto me"
    if itemName is not missing value then set msg to "'" & itemName & "' is not a folder"

    display alert msg as warning buttons {"OK"} default button "OK"
end warnUser
0

This answer from Apple's support site explains it. The files need to have been indexed and show up in Spotlight before they can be found with a search in this manner.

Reference: Automator Filter Finder Items

The Find Finder Items and Filter Finder Items actions use spotlight metadata to produce their results. This means that any disks, folders, or files that you input into them must be indexed by spotlight, otherwise the actions will return an empty list. Open the Spotlight pane of the System Preferences app and check the following:

That the kind of file you are looking for is enabled in the Search Results tab. That the folders you are working with (or their parent folders or disks) are not excluded from spotlight in the Privacy tab.

As a rule, these two actions will work precisely the same way as a Finder search (using command-F), so you can double-check to see what results you will get that way.

also, when searching by file extension, don't include the dot!

1
  • 2
    I have the same behaviour in my Mac (Catalina). I can find the files using the exact same criteria in Finder, so they should be indexed and Spotlight-ed. But in Automator the files are not found.
    – Nevin
    Jan 28, 2020 at 4:12
0

I've been struggling with this Finer action too. I've been testing a folder action which filters incoming files to my Downloads folder and then processes them. In my testing it can take 2s or more for a new file to appear in the Spotlight index. So I've had to put a simple 'wait' at the top of the action script which seemed to work when it was set to 2s but recently I've had to increase it and 5s seems to be reliable. In practice this is no problem as I use the action script to shrink down and convert to JPEG photos I send to my laptop from my iPhone via AirDrop. 5s delay does not cause a problem.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .