Putting incomplete or cancelled downloads automatically to the trash?

Discussion in 'OS X Mountain Lion (10.8)' started by Jardins de Vin, Jun 30, 2013.

  1. Jardins de Vin macrumors 6502a

    Jardins de Vin

    Joined:
    Nov 6, 2012
    Location:
    Europe
    #1
    Is there a way to put files that you have started to download but which, for some reason, you have cancelled to download, or which happen to be incomplete, automatically to the trash or automatically deleting them right away?

    I don’t want to go to the Downloads folder and have to delete them manually each time.
     
  2. Partron22 macrumors 68000

    Partron22

    Joined:
    Apr 13, 2011
    Location:
    Yes
    #2
    I wrote an Applescript to accomplish this ages ago. It still works:
    Code:
    -- Looks for files in the download folder containing ".part" etc
    -- and moves them to the trash
    -- BP 2010
    
    
    set exttolookfor to ".part"
    set php to ".php"
    set webpage to ".htm"
    set testlook to ".xyz" -- <-- just used for testing
    -- set prependedstr to " " <-- I prefer to just make em easy to find rather than moving to trah
    
    set src to ((path to home folder) as text) & "Downloads"
    --display dialog src
    
    set filenames to {}
    
    tell application "Finder"
    	copy ((name of every file of the folder src) as list) to filenames
    	set numfiles to the number of files in the folder src
    	--display dialog numfiles
    	set n to 1
    	repeat while n is less than or equal to numfiles
    		
    		
    		set oldnam to item n of filenames as string
    		
    		if oldnam contains exttolookfor or oldnam contains php or oldnam contains webpage or oldnam contains testlook or oldnam starts with "showthread" or oldnam starts with "browse" then
    			
    			--set newname to prependedstr & oldnam
    			--set the name of file oldnam of the folder src to newname
    			move file (src & ":" & oldnam) to trash
    			
    		end if
    		
    		set n to n + 1
    	end repeat
    end tell
    
    return
     
  3. Dalton63841 macrumors 65816

    Dalton63841

    Joined:
    Nov 27, 2010
    Location:
    SEMO, USA
    #3
    That script is pretty cool, but does have 2 basic flaws.

    1. Safari uses a .download suffix now.
    2. It can't be scheduled. If you schedule it to run and it executes in the middle of a download, it will move a file that is in the middle of downloading to the trash.
     
  4. Partron22 macrumors 68000

    Partron22

    Joined:
    Apr 13, 2011
    Location:
    Yes
    #4
    Oh dear, I failed to supply a complete solution to everyone's problems. ;)
    I use Firefox, don't care about safari.
    If you want total automation, you'll need to work out conflict resolution yourself, or find someone else to do it for you.
     
  5. Dalton63841 macrumors 65816

    Dalton63841

    Joined:
    Nov 27, 2010
    Location:
    SEMO, USA
    #5
    LMAO I was mostly just pointing out it may not help the OP.

    Actually though with just a little tweaking it would cover both issues I mentioned, although off the top of my head I'm not sure how to make it ignore currently downloading files.
     
  6. Partron22 macrumors 68000

    Partron22

    Joined:
    Apr 13, 2011
    Location:
    Yes
    #6
    Yeah, it's a starting point, that's all. The version I actually use includes a lot more file types, and fancier substring searches. As far as ignoring downloads in progress, you could probably prevent most problems by not moving anything to trash that's been modified in the last 12 hours. With a reasonable internet connection that should protect even most movie or OS downloads from premature trashing.
     
  7. jsdraven macrumors newbie

    Joined:
    Aug 14, 2013
    Location:
    Sonora, CA
    #7
    I would have get your script to grab today's date then during your loop before you compare the file name compare the creation date as it should be same day. just ignore the matches. If you need you may be able to do some math on the stamp and fine tune the time if that matters to you.
     

Share This Page