Organize Downloads Folder
Goal
Move each item in ~/Downloads into a topic folder that this skill made, so that only
topic folders stay at the top, and no item is lost or changed.
Quick start
List each item at the top of the folder, and mark the topic folders that this skill made:
cd ~/Downloads
for f in *; do if xattr -p organize-downloads-folder "./$f" >/dev/null 2>&1; then echo "TOPIC | $f"; else echo "$(file -b "./$f" | cut -d, -f1) | $f"; fi; done
- DO sort each item that is not marked
TOPIC: each file, each link, each app, and
each folder
- DO NOT move a hidden file, or a download that is not complete, such as
.crdownload,
.download, or .part; the browser can still be writing it
- DO NOT delete, rename, or change an item, and DO NOT run
rm in Downloads; the
user cannot get back an item that this skill loses
How to look inside an item
Find the topic from the content, not the name:
T="${TMPDIR:-/tmp/}organize-downloads-folder"; mkdir -p "$T"
for f in *; do [ -f "$f" ] || continue; echo "== $f"; case "$f" in *.p8|*.p12|*.pem|*.key|*.env|*.kdbx|*.ppk|id_*) echo PRIVATE; continue;; esac; t=$(mdimport -t -d3 "./$f" 2>&1 | sed -n 's/.*kMDItemTextContent = //p' | head -c 300); if printf '%s' "$f $t" | grep -qiE 'passw|secret|credential|api[_ -]?key|private[_ -]?key|[_-]token|token[=:"]|(recovery|backup) (code|key|phrase)|seed phrase'; then echo PRIVATE; else printf '%s\n' "$t"; fi; done
find "./<folder>" -not -name '.*' | head -30
sips -Z 900 -s format jpeg "./<image>" --out "$T/<n>.jpg"
head -c 2000 "./<text file>"
mdls -raw -name kMDItemWhereFroms "./<item>"
- DO get the text of every document with the
mdimport loop, in one command; it reads
PDF, Word, RTF, HTML, and plain text, and the file list of an archive
- DO find the topic of a folder from the names of its items, and read an item inside it
only when the names do not give the topic
- DO read each image with the Read tool, through its small copy
- DO read a file that the loop gives no text for with
head, or with the Read tool
through a copy that ends in the correct extension
- DO NOT read a file that the loop marks
PRIVATE, with any command; its name or its text
shows a key, a password, or a token, so find its topic from its name and its type only
- DO NOT open, mount, run, or install an app, a disk image, a package, or a script
- DO copy each name from the output of a command, or match it with a glob; macOS puts
a narrow no-break space before
AM and PM, so a typed space does not match
How to move the items
Make each topic folder with mkdir, and mark it; then move each item into it whole:
cd ~/Downloads
Z="${TMPDIR:-/tmp/}organize-downloads-folder/sizes"; stat -f '%z %N' -- * > "$Z"; sleep 5; stat -f '%z %N' -- * | diff "$Z" -
mkdir "<Topic>" && xattr -w organize-downloads-folder 1 "<Topic>"
ls "<Topic>/<name>" 2>/dev/null
mv -n -- "<item>" "<Topic>/"
- DO NOT move a file that the
diff prints; it still grows, so something still writes
it; run the diff again later, and move it when it prints nothing
- DO move a folder whole, with its items inside it; a folder that is not marked belongs
to the user, so DO NOT move an item out of it, or put an item into it
- DO put items only into a folder marked
TOPIC, or into a subfolder of one that you
make and mark the same way
- DO NOT add
-p to mkdir; it fails when any item has that name, in any case, and
-p hides that failure; choose another name for the topic when it fails
- DO name each folder after a topic, not after a file type, so that the items of one
task stay together
- DO put an item that has no topic into
Other, and say what it holds
- DO check for an item of the same name in the folder before each move; when one is
there, move the item into a subfolder that says how it differs, such as
Travel/Lisbon
How to verify
cd ~/Downloads
for f in *; do xattr -p organize-downloads-folder "./$f" >/dev/null 2>&1 || echo "$f"; done | grep -v -e '\.crdownload$' -e '\.download$' -e '\.part$'
find . -type f -size +0 -not -name '.*' -not -path '*.app/*' -exec md5 -r {} + | sort | awk '$1==p{if(!s)print q; print; s=1; next} {p=$1; q=$0; s=0}'
find . -mindepth 1 -maxdepth 2 -type d -not -path '*.app/*' | sort
rm -rf "${TMPDIR:-/tmp/}organize-downloads-folder"
- DO sort each item that the first command prints, then run it again; the user can add
an item while this skill runs, and it prints nothing only when the task is done
- DO tell the user about each pair that the second command prints; the two files are
the same, and the user decides which one stays
- DO give the user the tree of folders, with the number of items in each and one line
that says what each folder holds
Copyright © 2026 Lorenzo Mazzarotto
1---2name: organize-downloads-folder3description: Sorts the loose files and folders in the Downloads folder into subfolders by topic. Use when asked to organize, sort, or tidy the Downloads folder.4metadata:5 source: https://skillmd.com/skills/mazzsva/organize-downloads-folder6---78# Organize Downloads Folder910## Goal1112Move each item in `~/Downloads` into a topic folder that this skill made, so that only13topic folders stay at the top, and no item is lost or changed.1415## Quick start1617List each item at the top of the folder, and mark the topic folders that this skill made:1819```bash20cd ~/Downloads21for f in *; do if xattr -p organize-downloads-folder "./$f" >/dev/null 2>&1; then echo "TOPIC | $f"; else echo "$(file -b "./$f" | cut -d, -f1) | $f"; fi; done22```2324* **DO** sort each item that is not marked `TOPIC`: each file, each link, each app, and25 each folder26* **DO NOT** move a hidden file, or a download that is not complete, such as `.crdownload`,27 `.download`, or `.part`; the browser can still be writing it28* **DO NOT** delete, rename, or change an item, and **DO NOT** run `rm` in Downloads; the29 user cannot get back an item that this skill loses3031## How to look inside an item3233Find the topic from the content, not the name:3435```bash36T="${TMPDIR:-/tmp/}organize-downloads-folder"; mkdir -p "$T"37for f in *; do [ -f "$f" ] || continue; echo "== $f"; case "$f" in *.p8|*.p12|*.pem|*.key|*.env|*.kdbx|*.ppk|id_*) echo PRIVATE; continue;; esac; t=$(mdimport -t -d3 "./$f" 2>&1 | sed -n 's/.*kMDItemTextContent = //p' | head -c 300); if printf '%s' "$f $t" | grep -qiE 'passw|secret|credential|api[_ -]?key|private[_ -]?key|[_-]token|token[=:"]|(recovery|backup) (code|key|phrase)|seed phrase'; then echo PRIVATE; else printf '%s\n' "$t"; fi; done38find "./<folder>" -not -name '.*' | head -3039sips -Z 900 -s format jpeg "./<image>" --out "$T/<n>.jpg"40head -c 2000 "./<text file>"41mdls -raw -name kMDItemWhereFroms "./<item>"42```4344* **DO** get the text of every document with the `mdimport` loop, in one command; it reads45 PDF, Word, RTF, HTML, and plain text, and the file list of an archive46* **DO** find the topic of a folder from the names of its items, and read an item inside it47 only when the names do not give the topic48* **DO** read each image with the Read tool, through its small copy49* **DO** read a file that the loop gives no text for with `head`, or with the Read tool50 through a copy that ends in the correct extension51* **DO NOT** read a file that the loop marks `PRIVATE`, with any command; its name or its text52 shows a key, a password, or a token, so find its topic from its name and its type only53* **DO NOT** open, mount, run, or install an app, a disk image, a package, or a script54* **DO** copy each name from the output of a command, or match it with a glob; macOS puts55 a narrow no-break space before `AM` and `PM`, so a typed space does not match5657## How to move the items5859Make each topic folder with `mkdir`, and mark it; then move each item into it whole:6061```bash62cd ~/Downloads63Z="${TMPDIR:-/tmp/}organize-downloads-folder/sizes"; stat -f '%z %N' -- * > "$Z"; sleep 5; stat -f '%z %N' -- * | diff "$Z" -64mkdir "<Topic>" && xattr -w organize-downloads-folder 1 "<Topic>"65ls "<Topic>/<name>" 2>/dev/null66mv -n -- "<item>" "<Topic>/"67```6869* **DO NOT** move a file that the `diff` prints; it still grows, so something still writes70 it; run the `diff` again later, and move it when it prints nothing71* **DO** move a folder whole, with its items inside it; a folder that is not marked belongs72 to the user, so **DO NOT** move an item out of it, or put an item into it73* **DO** put items only into a folder marked `TOPIC`, or into a subfolder of one that you74 make and mark the same way75* **DO NOT** add `-p` to `mkdir`; it fails when any item has that name, in any case, and76 `-p` hides that failure; choose another name for the topic when it fails77* **DO** name each folder after a topic, not after a file type, so that the items of one78 task stay together79* **DO** put an item that has no topic into `Other`, and say what it holds80* **DO** check for an item of the same name in the folder before each move; when one is81 there, move the item into a subfolder that says how it differs, such as `Travel/Lisbon`8283## How to verify8485```bash86cd ~/Downloads87for f in *; do xattr -p organize-downloads-folder "./$f" >/dev/null 2>&1 || echo "$f"; done | grep -v -e '\.crdownload$' -e '\.download$' -e '\.part$'88find . -type f -size +0 -not -name '.*' -not -path '*.app/*' -exec md5 -r {} + | sort | awk '$1==p{if(!s)print q; print; s=1; next} {p=$1; q=$0; s=0}'89find . -mindepth 1 -maxdepth 2 -type d -not -path '*.app/*' | sort90rm -rf "${TMPDIR:-/tmp/}organize-downloads-folder"91```9293* **DO** sort each item that the first command prints, then run it again; the user can add94 an item while this skill runs, and it prints nothing only when the task is done95* **DO** tell the user about each pair that the second command prints; the two files are96 the same, and the user decides which one stays97* **DO** give the user the tree of folders, with the number of items in each and one line98 that says what each folder holds99100Copyright © 2026 Lorenzo Mazzarotto