Specific Folder Action doesn't work

Discussion in 'Mac Basics and Help' started by waffles123, May 29, 2010.

  1. waffles123 macrumors regular

    Joined:
    Feb 23, 2009
    #1
    Hey, I've been experimenting with folder actions for a few days, and there is one folder action I can't get to work. I'm trying to automatically remove dmgs from my downloads folder into the trash. This is what it looks like: [​IMG]
     
  2. calderone macrumors 68040

    calderone

    Joined:
    Aug 28, 2009
    Location:
    Seattle
    #2
    The problem is that the way it is setup you will never target the things you want to target. Here is what it is doing now.

    Synopsis of Automator Action:
    When items are added to ~/Downloads take those added items and return only items with the extension dmg and that have not been opened in the last day, move the items that meet these criteria to the trash.

    The Problem:
    The problem is that you are only targeting items that are added to the downloads folder, not items that would also match the criteria of having been opened a day ago because those items aren't being passed through the folder action. In others words, the dmgs that have been in your downloads folder for the last few days and haven't been opened aren't touched by the action because the action only receives newly added items.

    Now, technically, there should be some dmgs that get filtered, as when they are downloaded many come with a date last opened that is far in the past (unless Safari is mounting them automatically).

    What you should do instead:
    What you want to do is utilize scheduled tasks. This can be done in a number of ways, the easiest way would be iCal but you can also use launchd.

    In iCal you can attach scripts and other things to be run at a certain time. In this case, you would want to create an Application in Automator and have iCal open the application you created.

    Here is a new sample action that should get you started.

    Alternative:
    You could simply attach the action I have shown here to the folder, that way it is filtering existing finder items, but it will only be run when new items are added to the folder.

    If you chose this route, you would need to create a Folder Action, and not an Application. However, you wouldn't need to pass the input (the added items) to the workflow, so you could break the connection although leaving won't do any harm.

    Take into consideration what I mentioned above, downloaded DMGs, unless automatically mounted by Safari may have a "Last opened" date that meets your criteria and as such they may be trashed.
     

    Attached Files:

  3. waffles123 thread starter macrumors regular

    Joined:
    Feb 23, 2009
  4. waffles123 thread starter macrumors regular

    Joined:
    Feb 23, 2009
    #4
    I'm having some trouble again. I changed it instead of dmgs, any file that I haven't opened in a day in my downloads folder gets deleted. Instead, any file downloaded gets instantly put into the trash. Here's my workflow: [​IMG]

    Thanks
     
  5. calderone macrumors 68040

    calderone

    Joined:
    Aug 28, 2009
    Location:
    Seattle
    #5
    As I mentioned above, downloaded files may have a "Last Opened" date that matches your criteria.

    I think a scheduled action, as opposed to a folder action would be a better bet.

    As it stands, anytime something is added to the downloads folder the folder action is being executed. And it will be executed on any items in the Downloads folder, including newly downloaded items.

    Part of them problem is that when a file is downloaded it comes with all the metadata that was there when the file was put on the location you are downloading it from. Because of this, it wouldn't even be feasible to filter out those items based on when it was downloaded.

    EDIT: I was thinking and thought of a way to fix this problem.

    By touching the files that have been added to the Downloads folder when the action runs, we are removing them from the items that meet your find criteria.

    See the screenshot.
     

    Attached Files:

  6. waffles123 thread starter macrumors regular

    Joined:
    Feb 23, 2009
    #6
    Thanks a bunch for that script, calderone. It works perfectly on pictures, but it doesn't work on dmgs. However, there is one problem: When I download a dmg, Safari puts it in the download folder, but it is recognized as a Safari download (it has .download as the extension), and not a dmg. When it automounts, Safari removes the .download, and replaces it with the dmg. The shell script doesn't work because it is long after the file has been put into the folder. As a result, the date opened/modified is unchanged.

    Picture before it automounts:

    [​IMG]

    Picture after the dmg is mounted:

    [​IMG]
     
  7. calderone macrumors 68040

    calderone

    Joined:
    Aug 28, 2009
    Location:
    Seattle
    #7
    No problem. I would add in the "Pause" action, which is available in Automator. Adding it to the beginning of the script would be one way to solve the problem.

    Of course, it is tough to say how long it should wait.

    I have an idea for a better solution. I will work through it tomorrow and post it.
     

Share This Page