12/10/10
12:14 pm

MacMost Now 488: Automator Folder Actions

You can use Automator to alter what happens when a file is added to a folder. In this example, new files added to a folder are then sorted into subfolders according to their type. You can add multiple actions to a folder and then determine which order they are used.

Video Transcript (Click to Expand)
Hi, this is Gary from MacMost Now. On today's episode let's use automator to sort files into folders. So one of the things you can do with automator is to create a folder action. That's an action that occurs when a new file is added to a folder. So, for instance, you can set it to sort files when you put, say, an image into a folder it does something with it, when you put a sound file into a folder it does something else with it. Let's go and take a look at a simple example. Let's create a new folder on the desktop, and we'll call it sorter. And then inside it, we'll create some other folders. Let's call one images. Let's call another one sound. Let's call another one other. Now the idea is that we drop something into this sort of folder, it will then place it in the proper sub folder, depending on what file type it is. So we're going to do this with automator and we're going to do it without using any apple scripting just automator functions. So what we're going to do is create a folder action in automator and choose it. Now, the next thing we need to do is choose the folder that it's going to act on. So we're going to go to the desktop and choose our sorter folder. So first we're going to narrow it down to just files and folders. And then we're going to look in here and find the filter finder items. The input here is the file and folders that are added to the sorter folders so we have it narrowed down that far. Now we just want to go and set it to ones where the kind is an image. Next thing I want to do is then move finder items, so we drag that over here so see the results of this flow into this one. And we're going to move it to select other. And we'll select this images folder. There, so it's going to take whatever is put into the sorter folder. Filter it by kind of image and then move those to the images folder. So now we're going to save this and give it a name. So we're going to do, say sorter images and save that. Now it's already assigned to that folder, so we'll just hide automator and we will drag and drop this image I have here into the sorter folder. We do that and then we give it a second, see it disappears. If we look in images we can see we put it inside that images folder. So now we want it to sort by the other criteria as well. So we're going to switch back to automator and we're going to create a new thing, we're going to do a new folder action. And we're basically going to repeat these steps and create one for audio files. We can get a sample file like this mp3 here, drop that into sorter, and we can see it will disappear into sound folder. So and last we want to create another folder action and this is going to handle all the other files. So we will choose the sorter folder as before but this time we're just going to say move finder items. You don't need to filter you just need to deal with everything else. So here's a document, we're just going to drag that into here. And that should disappear into the other folder. So to see what folder actions are applied to a folder, you select the folder. Control or right click it and go to folder actions set up. Then it's going to want you to add a new folder action to it. Instead of doing that we're just going to do cancel to see what folder actions are there. All the folders have folder actions on the left and on the right with this one selected you can see which folder actions have been applied and you can turn them on or off. You can also select one here and click edit workflow. That's a quick way to be able to go and edit a file action without having to find the file on your drive. Now order is important here you want to make sure it does images, audio and then other last. So if you want to change the order then you remove the item there from the workflow and then you can add one back in so you can add audio back in there. You can see I added it last. By the way, if you ever want to see where these files are kept then you need to go to your user folder library and then under library you go down to workflow. And there you'll find applications, folder actions, and there are the three workflows that we created. So while we've created a special folder called sorter for this, you can actually use an existing folder. For instance your downloads folder say have subfolders for pdf, images, music, all sorts of things. And then use criteria more than just kind. You can use file name checks you can use extension checks. You can do all sorts of rules to actually filter anything that gets thrown into your download folder into subfolders. It's a way to keep things neat. So there's a way to use automator to add folder actions to folders. Hope you found this useful, till next time this is Gary with MacMost Now.

Comments: 27 Responses to “MacMost Now 488: Automator Folder Actions”

    Vinz
    12/10/10 @ 4:20 pm

    Gary, just wanted to thank you for making things so easy. I’m a new mac user and became a follower of your website a few months ago.Wonderful and useful tutorials.
    Keep up the good job!
    Thanx

      Edward Bennett
      2/5/12 @ 12:15 pm

      Just wanted to say i really appreciate your video tutorials on all the subjects you cover . They’re a big help . Thanks Edward Bennett

    Kika Wai'Alae
    12/10/10 @ 7:37 pm

    I follow your instructions and it works for images however you say do the same thing on sounds etc. Well I must be missing something because my songs go into other. So is it kind is music? You don’t go step by step only repeat the steps. I’m lost help…

      12/10/10 @ 11:20 pm

      Right “Music” — you will want to repeat the same workflow, but choose “Music” as the kind to filter by, and then move to the folder named “Audio” if you follow the same naming as I show. You can choose any criteria you want, not just “kind” — so explore the different options available to you to find some that suit your needs.

    Kika Wai'Alae
    12/11/10 @ 3:11 am

    Ok thanks. Oops after playing around in there and moving a music file my iTunes will not open. Did I mess up my iTunes? :(
    Message says iTune folder is on a locked disk or you do not have write permission for this folder.

      12/11/10 @ 9:23 am

      Sounds like you either changed permissions of you Music folder or iTunes library, or you moved one of them or a subfolder. Or,Mir could be unrelated. Id have an expert take a look.

    Kika Wai'Alae
    12/11/10 @ 9:49 am

    Thanks Gary, I had an Apple tech on the phone for over an hour and he was stumped too. We really didn’t change anything in there but after logging in to other accounts and restarting the machine a few times iTunes decided to behave. Must be the rainy Hawaiian weather out here playing games with my BigMac. Thanks for your help, I will once again try to figure this automator thing out.

    Aloha
    Kika

    Drew
    12/13/10 @ 10:14 am

    Hi Gary,

    There must be something wrong with my system (10.6.5). When I create the actions, only the first one in the list works. I even tried creating a new user account and still no joy. I also had a problem with pasting icons into Photoshop a few weeks ago (MacMost #465). It doesn’t seem worthwhile for such small problems, but I don’t see any solution other than a clean install of the OS, apps, and data.

    Drew

    Mex
    12/14/10 @ 5:23 am

    Where’s the flattr-button? I’d like flattr this episode…

    Scott Pesetsky
    12/16/10 @ 11:42 am

    Hi Gary,

    Thanks for the great lesson. Can I use this process to have Acrobat OCR a document and then save it?

    Scott

      12/16/10 @ 11:44 am

      Check to see what Actions that Acrobat adds to Automator (maybe none?). An application like that would typically add actions if it supports Automator. See if one of those actions will help you create a workflow that does what you want.

    Benjamin
    4/14/11 @ 10:06 pm

    I try this very helpful hint and I get this error message in Automator when I try to “Save As” when I try to close the program:

    “You don’t have permission to save the file “Folder Actions” in the folder “Applications”. –To view or change permissions, select the item in the Finder and choose File > Get Info.

      4/14/11 @ 10:18 pm

      Just save it elsewhere. Create a folder in your Documents folder to hold scripts you make.

      Kevin
      10/26/11 @ 6:35 pm

      I see you didn’t really get an answer and I was having this same problem. For me, it didn’t matter what folder I tried to attach the script to, I always go this error, indicating permissions issues. Even after fixing disk permissions, no go. So here’s what works:

      Go to /Users/YourUserName/Library/Workflows/Applications and make the whole directory tree readable and writable to you.

      I’m not sure why its not writable to us by default, but after much searching and trial and error, I figured it out and it works. You can make the directories readable and writable in the terminal or just get info on each folder and do it that way.

    Cadillac
    5/31/11 @ 9:43 am

    Gary,
    When I try to configure folder actions, I get an error message: Connection failed server does not exist… That just keeps looping. It calls for a server that I don’t have any longer.
    What do I do to make it stop?

      Cadillac
      5/31/11 @ 9:47 am

      And, automatically add to itunes is in red.

        5/31/11 @ 9:51 am

        Perhaps you still have an alias or Finder sidebar item that links there? I would just experiment to see if you can get around that error, or figure out what may still be expecting that server to be there. In the Finder when you go Command+K, is the server listed? If so, remove it.

    bj_110
    9/12/11 @ 6:55 pm

    Gary,

    I’ve followed your Automator instructions to the letter on my Mac OS 10.5.8 and it refuses to work. I’ve enabled folder actions added the workflow, removed it, started the same one again, then added it, but still nothing. All I want to do is automatically move any file from my folder called ‘scans’ that’s been dropped in there by my network scanner (it has to be a shared folder with full read/write permissions for the scanner to work) and move it to another non-shared folder so the items scanned can’t be viewed by anyone else on the network. I’m at a loss as to why it’s not working

      9/12/11 @ 7:11 pm

      Not sure. Maybe a problem with Leopard (vs Snow Leopard). Does it work if you drag and drop them in there (as opposed to them being created by the scanner)?

      bj_110
      9/12/11 @ 7:16 pm

      Sorry, it’s 10.6.8 Snow Leopard not Leopard as previously mentioned.

    bj_110
    9/12/11 @ 7:17 pm

    It still doesn’t work if I manually drop them in there from another folder.

      9/12/11 @ 7:48 pm

      Not sure. Hard to say without being there. Perhaps have someone who has done some Automator work before give you a hand. Or, visit the Apple store and see if you can get some instruction. Or, just continue to try to trouble-shoot the problem and see if you can figure it out.

        guebert
        7/20/12 @ 8:26 am

        Hi Gary, I tried your workflow and it did not work on my computer. No error message just no effect. After some googleing I learned that the “Filter Finder items” action only works on items that have been indexed by Spotlight.
        As I have disabled the indexing of my HD this workflow did not work. Maybe some other viewers have had the same experience. Anyway, love your vidcasts, please keep up the great work.

    Ivan
    11/6/11 @ 12:36 pm

    Thanks everybody for your ideas.
    Could someone post an Automator workflow example for the following:
    I want to find folders that contain ONLY one kind of file but which does not contain any other, i.e., I want to search inside my music folders and find any folder that contain only .jpg files, but no music files on them.

      11/6/11 @ 7:10 pm

      That will probably require some AppleScripting (using the AppleScript programming language inside of Automator). Tough to do if you are not a programmer, I’m afraid.

    Adam Davidson
    3/31/12 @ 5:16 am

    Hi Gary, thanks for the great tutorial.

    I have a conundrum for you: I want to do something like this on my downloads folder, but for example, move new episodes of “CSI” to the CSI folder, new episodes of “The Mentalist” to the Mentalist folder, etc… Your tutorial is great, however I’ve got 30-odd shows on a scheduled download. Do I have to create a folder action for each show I add? or is there a way to automate this based on checking the filename against a list of existing folders into which they should go?

      3/31/12 @ 7:19 am

      You might be able to do that using some AppleScript — if you know how to program.

Comments Closed.