Skip navigation

Moving files to the Trash with Automator

3295 Views 5 Replies Latest reply: Nov 16, 2013 1:01 AM by Aminabot RSS
MAMEBase Calculating status...
Currently Being Moderated
Aug 3, 2009 7:47 PM
I'm having some problems with Automator, and I'm hoping it's just a simple step I'm missing.

I have a list (text file) of a group of files I wish to remove from a folder (about 650 or so files, from a folder of about 8000). I have been able to get Automator to read the text file, and show me the result.

(Ask for Finder Items (Files & Folders), Combine Text Files (Text), Filter Paragraphs [Return Paragraphs That Are Not Empty] (text))

This results in showing me my list of files I wish to remove.

I don't quite get how to pass this list on to the Finder to tell it to select these files, and move them to the trash.

Any assistance would be appreciated.
Power Mac G5, Mac OS X (10.5.7)
  • red_menace Level 6 Level 6 (14,275 points)
    Currently Being Moderated
    Aug 4, 2009 4:35 PM (in response to MAMEBase)
    The Move Finder Items to Trash action should do what you want, if you are providing the complete file path. How are your files defined in the text file (name only, POSIX path, etc)?
    MacBook Pro, Mac OS X (10.5.7), /  G4 Digital Audio, G4 mini [Tiger 10.4.11]  /  G3 MiniTower [OS 9.2]
  • red_menace Level 6 Level 6 (14,275 points)
    Currently Being Moderated
    Aug 4, 2009 9:24 PM (in response to MAMEBase)
    Since your text file just has the names, an action is needed to build the complete file path. Most of Apple's text and file actions don't use variables, but a Run AppleScript action can be used to fill in the blank. Give this workflow a try (I haven't tested it with a large number of files, so I don't know how slow it will be):

    1) Ask for Finder Items {Files} -- choose the text file
    2) Combine Text FIles
    3) Filter Paragraphs {Return paragraphs that are not empty}
    4) Run AppleScript -- paste the following script:
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    font-weight: normal;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #FFEE80;
    overflow: auto;"
    title="this text can be pasted into an Automator 'Run AppleScript' action">
    on run {input, parameters} -- build file paths from a list of names

    set output to {}
    set SkippedItems to {}

    set TheFolder to (choose folder with prompt "Select the folder containing the files:") as text

    repeat with AnItem in the input
    try
    set AnItem to (TheFolder & AnItem)
    get AnItem as alias -- test
    set the end of the output to the result
    on error
    set the end of SkippedItems to AnItem
    end try
    end repeat

    if SkippedItems is not {} then
    display alert "Error with AppleScript action" message ((count SkippedItems) as text) & " items were skipped (file not found)"
    end if

    return output
    end run</pre>
    5) Move Finder Items to Trash
    MacBook Pro, Mac OS X (10.5.7), /  G4 Digital Audio, G4 mini [Tiger 10.4.11]  /  G3 MiniTower [OS 9.2]
  • Aminabot Level 1 Level 1 (0 points)
    Currently Being Moderated
    Nov 16, 2013 1:01 AM (in response to red_menace)

    Hey red_menace,

     

    You once helped me with a similar issue by writing me almost the exact same Applescript.

     

    It's worked like a charm for a long time... until Mavericks.

     

    It basically comes back with all of the items skipped. Any thoughts on why?

     

    Thanks for taking a look! 

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.