Gather Finder Items Into A New Folder With An Automator Service

Organising the clutter on your hard drive can be a pretty tedious task. This Mac OS X service will help speed things up by letting you throw groups of files into a new folder with just one click.

If you're anything like me, you have a folder somewhere on your system (like the Downloads folder or the Desktop) where a lot of junk accumulates. When it gets too cluttered, you have to clean it up — which can get annoying when you have to make new folders and drag files around. With this service, all you need to do is select some files, right click on them, and hit a context menu item to throw them into a new folder.

To create the service, just open up Automator and choose Service at the menu that pops up. Set your service to receive selected files from the Finder at the top of the workflow, and drag in the Run Applescript action. Copy the following code into the box, being sure to replace only the (* Your script goes here *) line (and not the prepopulated lines at the beginning or the end):

tell application "Finder" (* what files do you want to gather into a new folder? *) set selectedItems to selection if selectedItems is not {} then (* topLevelName assures the uppermost file-level-directory will be selected in case of multiple selections in list or column view. *) set topLevelName to name of item 1 of selectedItems (* silly set of workarounds to override vanilla AppleScript's lack of permission when playing in the .Trash folders *) set selectionPath to POSIX path of file ((item 1 of selectedItems) as string) set selectionPath to ((characters 1 thru ((offset of topLevelName in selectionPath) - 1)) in selectionPath) as string (* Modify path string to create a unique target folder using date and time *) set dateString to do shell script "date "+%Y.%m.%d %a %I.%M.%S %p"" -- this line broken out for easy editing set newFolder to selectionPath & (dateString & " Gathered Items") -- rearrange as you please; is set this way for proper name sorting (* more workarounds to allow playing in the .Trash *) do shell script "mkdir " & quoted form of newFolder set newFolder to (POSIX file newFolder) as alias move selectedItems to newFolder reveal newFolder end if end tell

When you're done, your service should look exactly like the image to the left. If it does, just save the Service as whatever you want, and you'll be able to access it from Finder's context menu or the Apple menu whenever you select a group of files. It will automatically create a new folder and put those files in it, ready for you to rename and continue organising.

Gather Finder Items with a new Service [Mac OS X Hints]


    Awesome! Thank you!! will try this one when i get home!

    How can i make my automator look nice like this one in the last ss?

    Mine is all purple and don't have indentation.

Join the discussion!