Way to move files to multiple folders in single Folder Action

automationautomator

I'm trying to set a Folder Action that will move all of the files that are in my downloads folder into their appropriate folders so that I don't have to do them manually. (movies to movie folder, music to music folder etc…)

Is there a way I can do this in a Folder Action without having to create separate Folder Action script for each type of file?

Best Answer

You can use a shell script like this:

for f; do
  case $f in
    *.mp3|*.m4a) mv -n "$f" ~/Music;;
    *.jpg) mv -n "$f" ~/Pictures;;
    *) mv -n "$f" ~/Documents;;
  esac
done

mv -n skips a file when a file with the same name exists in the target.