Automatically Organize Files With an Automator Folder Action Shell Script

By using a Shell script in an Automator Folder Action you can create a "drop zone" folder that moves any file placed into it. By using a Shell script it is easy to add new conditions and destination folders.

Here’s the script I’m using in the video:

for f in "$@"

	if [[ $f == *"dailyreport"* ]]
		DEST="/Users/macmost/Documents/Daily Reports"
	elif [[ $f == *"tpsreport"* ]]
		DEST="/Users/macmost/Documents/TPS Reports"
	elif [[ $f == *".txt" ]]
		DEST="/Users/macmost/Documents/Text Files"

	if [[ $DEST != "" ]]
		osascript -e "display notification \"Moved $f to $DEST\""
		mv $f $DEST
		osascript -e "display notification \"$f Not Moved.\""

Comments: 3 Responses to “Automatically Organize Files With an Automator Folder Action Shell Script”

    Sumanth Kumar
    4 months ago

    Shouldn’t there be ‘then’ after every elif?

    4 months ago

    Sumanth: Not in a shell script. Try it and see.

    3 months ago

    Hi, this was really helpful – I’m a very amateur coder and have never done shell script before. The one bit of feedback I have is that I couldn’t get this to work without adding a ‘then’ after every ‘elif’. That was the case with /bin/zsh and /bin/bash (the default) whatever those mean… Otherwise, really useful and has got me started. All I need now is to understand more conditional arguments such as AND, OR etc. Also, would be really helpful to understand how to add tags to files! Thanks!

Comments Closed.