Previous 1 2 Next 21 Replies Latest reply: May 23, 2012 2:42 PM by Darren Hatch
Caramby Level 4 (1,515 points)

A very simple task, which I have attempted to figure out many times over the last few months; but my repeated attempts haven't been successful. This should be easy for someone to resolve…


I would like to strip out all the files of a certain extension (.txt) from an hierarchy of nested folders, & move them to the Trash. (Told you it was easy!)


Here's what I think ought to work:


• Create an Automator Workflow

• 'Ask for Finder Items' to select the topmost folder

• 'Get Folder Contents' with 'Repeat for each subfolder found' — (the results successfully include all the relevant files)

• 'Filter Finder Items': "find files where any of the following are true: file extension is .txt" — (I tried "txt" as well as ".txt")

• 'Move Finder Items to Trash'.


The files turn up (alongside loads of other junk) in the 'Get Folder Contents' step, & they are reported in the results; but when I try to filter out everything apart from the .txt files, so that only the .txt files remain, the filter reports no results.


So the 'Filter Finder Items' action completes with no results, & with a warning that: The action “Move Finder Items to Trash” was not supplied with the required data.


I think it must be something obvious, but I can't figure it out, & although I've searched extensively online, everyone else with similar problems has other complications which get resolved… so they lose interest just at the point where I think they're going to reveal the solution.

27" iMac 3.06 GHz Intel Core 2 Duo, Mac OS X (10.6.5), Logic Studio 8.0.2, Occam's Razor Pro
  • Barney-15E Level 8 (46,329 points)

    Have you tried File Extension Contains txt? Or Ends with txt?

  • red_menace Level 6 (15,125 points)

    Hmmm - I couldn't get the Filter Finder Items or Find Finder Items actions to work either.  I tried a variety of booleans and terms (not just name extensions), and couldn't get the actions to output anything.


    Not sure what the problem is, but in the mean time you can try a Run AppleScript action instead:


    on run {input, parameters}
         set output to {}
         tell application "Finder"
              repeat with anItem in the input
                   set anItem to contents of anItem
                   if name extension of anItem is "txt" then
                        set end of the output to anItem
                   end if
              end repeat
         end tell
         return output
    end run
  • Caramby Level 4 (1,515 points)

    Yes — I tried every variation I could think of!

  • Caramby Level 4 (1,515 points)

    Many thanks — your script did indeed find 748 .txt files in a folder of 87550 items in 1055 seconds. I'm not sufficiently familiar with AppleScript to write my own scripts or to modify yours; I will need to find out how to do so (e.g., to include html files as well as text).


    However, the next action, Move Finder Items to Trash, failed: "Finder could not move the specified items to the Trash."


    Another mystery.


    But the thing I would most like to know is why the Filter Finder Items action doesn't work.


    When I first looked at this problem, I assumed I was under a misapprehension as to what this action is for, or that I had left out some essential steps to get it to work; but it seems my initial guess as to what it is supposed to do was correct. Except that it doesn't work.


    This is galling on two counts; firstly, that every time I think I can speed up a task by using Automator, it turns out the task requires this action (but can't get it to work). Which makes Automator a bit of a disaster from my point of view.


    Secondly, that if this is a bug, it's a bit of a biggie. Surely by now lots of people would have been reporting it?

  • Caramby Level 4 (1,515 points)



    The Move Finder Items to Trash action isn't completely failing; it is moving a few items to the trash, but then it gets stuck & won't do any more. The laborious workaround is to quit Automator so that the items in the Trash are no longer 'in use', empty the Trash, relaunch Automator, rinse, repeat, again, & again, & again… which would take ages for 748 files!


    There must be a better solution to that problem, as well. If no-one proposes one, I might have to ask it as a separate question (since it concerns a different action).

  • red_menace Level 6 (15,125 points)

    I haven't had a problem using those actions before, and although they haven't been modified, perhaps some underlying utility got changed in a recent OS update.  Some of the actions are just front ends to a shell script, for example the Find Finder Items action would just be using the find utility - I tried this action after checking for a conversion problem with items being input to the Filter Finder Items action, but in a workflow with just a single Find Finder Items action I was unable to get an output.


    Usually Automator includes error messages in its log, so you might check that to see if there is a problem with permissions, etc, when trying to move them to the trash.


    Automator has always had issues with goofy problems such as this (the Watch Me Do action is infamous), so it isn't really used as much as it should be, but this seems to be relatively new.

  • Caramby Level 4 (1,515 points)

    I included the only available info ("Finder could not move the specified items to the Trash"); there wasn't any more in the log. Naturally, my first thought was a permissions issue, but there doesn't seem to be anything wrong with the permissions. Now I'm wondering if the Finder has gnarled-up the directory structure somehow.


    As for how long this problem has been going on… unfortunately, I haven't logged when I first started using Automator, but as I say, I hit this snag right away. I'm sure it was at least several months ago, & I'd be inclined to say it was over a year — before I upgraded from my G5 to this iMac.


    Since it seems you have tried recreating this simple workflow, & you are getting the same failure to pass any results through the filter, then I would say there is definitely something up. This is very frustrating, because it means that at the moment Automator is 'unfit for purpose' as far as I'm concerned, & yet I don't want to give up on it & I don't know of a better solution. You would think with a Unix-based OS this kind of task would be a doddle. And I don't have the spare capacity to learn AppleScript on top of everything else I'm having to deal with at the moment!


    The glitch seems to strike where Get Folder Contents is supposed to pass its results to Filter Finder Items. Since Filter Finder Items then spends a lot of time processing, I would guess that Get Folder Contents has done its job; but of course I couldn't swear to it.


    I will keep experimenting, & I would be very grateful to hear of any more results you might get. I also think it would be very useful to hear from anyone else who has had similar problems with Filter Finder Items; maybe we can learn from their experience. I find it hard to believe it's just broken — but perhaps that really is the answer!


    Let's hope not…

  • twtwtw Level 5 (4,925 points)

    I think the problem is that the Move Finder Items to Trash action is buggy.  Remove that, and replace it with a Run AppleScript action that contains the following:


    on run {input, parameters}

              tell application "Finder"

                       delete input

              end tell

    end run


    That should clear up the problem.

  • Caramby Level 4 (1,515 points)

    Blimey, that did actually work — thanks. That would certainly deserve a 'helpful' if I had any left!




    It's a bit odd, though, that Move Finder Items to Trash is buggy. What's to go wrong? Surely it doesn't need to be much more complicated than the AppleScript you so kindly supplied?


    It's all a bit demoralising that there are all these bugs in what you might think would be simple actions. It's almost as if Apple no longer wish to support Automator, & force anyone who's that bothered to learn AppleScript instead. Which, as I said, I'm not too keen to take on. And anyway, I don't mean in any way to knock Apple or support any conspiracy theories, which are anathema as far as I'm concerned. (Red herring…)


    I would still dearly like to know for sure if Filter Finder Items is genuinely buggy, because if not I will be able to use it for all the tasks that I have lined up which seem to require it.


    And I've still got a "Correct Answer" up my sleeve for whoever can give a definitive answer to that one…

  • twtwtw Level 5 (4,925 points)

    You need to understand the issues here. Automator was released with 10.4 (Tiger), and many of the core automator actions date from that time.  This introduces forward-compatability problems: things that should work (and maybe did work) in 10.4 might not work as specified in 10.6, depending on if/how the underlying cocoa APIs have changed.  Now, in the best of all possible worlds, Apple would update automator actions with each new upgrade, but it's probably not needed for the bulk of the actions, and Apple may not be aware of problems that do exist with given actions (that depends on whether people filed meaningful bug reports on them).


    Don't be confused by the seeming simplicity of what I did: the Move Finder Items to Trash action probably uses cocoa file system APIs directly, whereas my applescript leverages the developed programmatic underpinnings of the Finder - the Finder has a built-in system for moving files in bulk, whereas the action is obviously moving files one at a time (which is where things are getting congested).


    Filter Finder Items seems to be a simple metadata search (just another use of the spotlight framework, which hasn't changed much since its inception) so I can't see any way in which it would fail.  it is, of course, limited by the same things that spotlight is limited by - it won't find material that's not indexed and may not do exactly what one always expects (e.g., may not recognize an extension as an extension unless the extension belongs to an app registered with the system) but other than that there's very little it can do wrong.  As a general rule, actions that deal only with manipulating automator data (e.g. modifying references passed from one action to the next) won't break.  You'll only see breakage with actions that need to access exterior frameworks that have changed significantly since the actions were created. 


    That's the best answer you're going to get: one can't prove a negative, so there's no way to demonstrate that FFI isn't broken.  it's easy enough to check for a given task, though - just run the workflow you have on a test folder without the deleting action, check the results window, and compare it to the results you expect (which you can gather by eye in a Finder search window, through an applescript, through an app that will report the number of files of given types in a folder…). 

  • Caramby Level 4 (1,515 points)

    I understand & appreciate your first two paragraphs. However, I need to ask questions to better understand you.


    You say that Filter Finder Items won't find material that's not indexed. If this is definitely true, then that could explain why it isn't producing any results; I have been testing these workflows on new material, which hasn't been on my system long enough for indexing to take place. That would be fine, except that indexing would seem to be an unnecessary luxury for the tasks I would prefer this action to perform — & there doesn't seem to be a simpler alternative. IOW, surely it doesn't require indexing for every possible filtering action, & if so, why is there no error message when only unindexed material is passed to it?


    I did say it in the OP; the task is to identify files hidden in a heap of folders & process them (e.g. by trashing them). I assumed Filter Finder Items would be able to do this, but couldn't get it to do so — & when red_menace tried the same thing, the results were equally unfruitful (assuming I've read those posts correctly).


    In my very simple original workflow, Get Folder Contents appeared to identify the correct files along with many others, but then Filter Finder Items produced no results. (N.B.: not partial results; no results at all.) Therefore either the identified files weren't properly passed to Filter Finder Items, or Filter Finder Items was failing to do what it says on the tin.


    The reason I'm restating all this is because you said "I can't see any way in which it would fail… there's very little it can do wrong". So either I've completely misunderstood the purpose of this action (which I did suggest earlier), or it is doing wrong — & I'm not the only person to find this to be the case.


    What happens when you recreate my workflow (or anything similar)?

  • twtwtw Level 5 (4,925 points)

    This workflow:


    when I run it and select my documents folder, seems to do the trick - at least, it returns 1402 items, which checks out with what I get from the equivalent Finder search.  In fact, the results of Filter Finder Items ought to be exactly the same as the results you get from doing a Finder search with the same criteria.  Of course, my documents folder is fully indexed, and it's hard for me to get unindexed material - the indexing process is actually fairly rapid unless you're talking about HUGE folders of material. 


    I get the same result if I use the Find Finder Items action on its own. 


    The only difference I can see in software is that you're running 10.6.5 and I'm running 10.6.7, which ought to be inconsequential.


    Is that the workflow you're using?  and are you sure you didn't accidentally set the Filter action to ignore input?

  • red_menace Level 6 (15,125 points)

    I tried the same thing, both with and without the Move Finder Items to Trash action, and couldn't get an output - items were going in, but nothing I set for the filters would result in an output.  I thought that maybe there was a coercion issue with the file references passed to the actions, but a workflow containing a single Find Finder Items action also did not produce any output for me.

  • twtwtw Level 5 (4,925 points)

    ok then, it works for me, but not for you.  the question is why.

    • Is the disk/folder you're checking indexed?
    • Is the disk HFS+?
    • What happens when you try to do a normal Finder search for text files in that folder?
    • Is the folder/disk owned by a different account than the one you're using?
    • Anything odd about your setup?
Previous 1 2 Next