Automator: Service to move files into new subfolders based on file extension *within any selected folder*

by David   Last Updated September 27, 2018 08:12 AM - source

I've been searching for quite a while now but can't seem to find relevant instruction for this particular task. I'm brand new at this so apologies if I'm missing something basic.

Like many photographers I come back from a shoot with a card containing RAW (CR2), JPG, and MOV files all in a single folder. Once I copy this folder to my hard drive, I have to do the following actions, for which I would like to create a single service, so that I can run this same process for any folder I choose.

So here's what I'd like to automate:

  1. Create separate folders for Raw, JPG, and Video within selected folder.
  2. Identify files of each type and move them into the folders created in the first step.

I thought this would be simple, but the problem seems to lie in my need for this to be a generic service, not tied to any specific folder path. I need it to be repeatable for other folders, but I can't seem to figure out that essential versatility aspect.

I've already found and adapted an Apple Script (see below) which creates the subfolders I need. That part works fine as a service on its own. But I can't seem to perform the second step which would do the actual file-moving.

I know how to move files of a certain type to a specific folder but that's not what I need. I need all the JPGs in a certain folder to be moved to a new subfolder called JPG within the selected folder and likewise for the other file types. I understand how to filter those file types, but so far I can't figure out how to move them to a folder without having to specify a path, I don't know how to point to folders that don't yet exist. Even if I could, those paths will be different for each folder I need to work on.

Can any one give advice or point me to a relevant discussion?

Many, many thanks.


Here's the Apple Script for my subfolder creation service: subfolder script

Script text:

on run {input, parameters} set output to {} tell application "Finder" set {source_folder, source_name} to {it, name} of first item of input repeat with prefix in {"JPG - ", "RAW - ", "Edits - ", "Video - "} make new folder at source_folder with properties {name:contents of prefix & source_name} set end of output to result as alias end repeat

Note: The file-moving part of the automation won't involve my the "Edits - " folder. This is just a container for future files.

Related Questions

How to pause on playback after current track on VOX?

Updated November 13, 2017 12:12 PM