Choose the automation
Build a safe dry run
Preview every planned file or application action before allowing the automation to change real state.
10 minute lesson
A dry run shows what an automation would do, without doing it. Add a dry-run mode before the first destructive operation, while the script is young. It should print the exact source, destination, application command, or deletion it would perform.
The mechanics are one flag and one branch:
#!/bin/zsh
dry_run=0
if [[ "$1" == "--dry-run" ]]; then
dry_run=1
shift
fi
if [[ $dry_run == 1 ]]; then
printf "move %q -> %q\n" "$source" "$destination"
else
mv -- "$source" "$destination"
fi
The %q format matters: it quotes each path the way the shell would need it, so a filename with spaces or a stray quote shows up honestly in the preview instead of looking like two separate files.
Run the preview against real input before every first live run:
./sort-screenshots --dry-run
# move Screenshot\ 2026-08-03.png -> /Users/flavio/Projects/acme/media/acme-2026-08-03.png
Read each printed line as a question: is this the file I meant, going where I meant? If any line surprises you, you just found a bug for free.
Test duplicates, spaces, missing input, and an unexpected directory. A preview that hides edge cases is not a safety control. If the dry run reports three files and the live run touches forty, the preview lied, and it gave you false confidence at the worst possible moment.
That is the one real failure mode of this pattern: the two paths drift apart. Someone adds a deletion to the live branch and forgets the preview branch. Keep the decision logic shared and branch at the last possible moment, at the single line that mutates state. The example above does exactly that: both branches use the same $source and $destination, and only the final action differs.
My advice is to make a new automation default to dry-run mode and require an explicit --run flag for its first weeks. You will be surprised how often the preview catches something you were sure was fine.
Lesson completed