Create Placeholders for downloaded files

Mar 11, '11 07:30:00AM

Contributed by: Magnus Dredd

Since I work in IT in the education sector, I'm always looking for whatever things I can find that are free that help me get things done.

I often have a hard time keeping track of what I've downloaded, tested, and then discarded. This is what I use to address that issue.

I wanted a simple way to remind myself which not-so-useful files (driver, utility, whatever) I have downloaded without leaving them on the machine taking up space. Since I already use file labels and they're a very quick way to categorize files, I decided to use them to mark which files to create 'Placeholders' for.

The following command that will delete all files in a directory that are labeled 'Gray' and then will create a new file that does not use disk space as a reminder.

Open Terminal.app and type cd followed by a space, then drag and drop the folder containing the files you've labeled onto Terminal.app's window (which will enter the full path for you), and then hit return. Paste the following command into Terminal.app and hit enter and the files that are 'Gray' will be replaced with 'Placeholder' files with the same name.

[crarko adds: There were some errors in the scripts listed in the comments below; I've updated the scripts to reflect the changes.]

find . -exec mdls -name kMDItemFSLabel {} \; -exec mdls -name kMDItemFSName {} \; | awk -F " = " ' $2 ~ /1/{ getline; print $2 }' | sed -ne '/^".*/p' | awk '{ print "rm "$0"; touch "$0 }' | bash
The following command will show what files will be deleted.
find . -exec mdls -name kMDItemFSLabel {} \; -exec mdls -name kMDItemFSName {} \; | awk -F " = " ' $2 == "1"{ getline; print $2 }' | sed -ne '/^".*/p' | awk '{ print "rm "$0"; touch "$0 }'
If your web browser is set to ask where to save downloaded files, when you go to download the same file again it will append '-1' (Firefox) or '(1)' (Chrome) to the end of the file name, letting you know you've already downloaded this before.

The '1' in $2 ~ /1/{ getline refers to the label 'Gray.' The label colors can be specified by the following numbers:
[crarko adds: I haven't tested this one.]

Comments (8)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20110310184347161