OS X Finder has a number of features most users rarely use. One of them, which I've lately become a big fan of, are colour labels.
Setting the color label of a file or a folder is trivial: just right-click on it and select the color.
Some users will probably use the colour labels to organise their files, for example they may label red a file they often use to find it easier in folder with many files.
I'm more interested in how they can be integrated in an automated workflow.
Consider this example: John is working at an e-shop and one of his tasks is to study the competition. Whenever he finds something noteworthy at a competitive site, he takes a screenshot, sometimes more than one. At the end of the day, he picks the ones that should be shared with the rest of the team and copies them to a shared folder. And every now and then, he cleans his screenshot folder, by deleting all screenshots that are older than a month, but not the ones he shared with his team.
Using colour labels, and a tool like hazel he could automate his workflow like this:
- label "green" the interesting shots.
- have a hazel rule that copies all green files to a shared folder, and then label them "blue".
- have a hazel rule that deletes all files older than a month, but not the ones that are colored.
The nice thing with this approach is it's very easy for John to have an overview of what's going on just by looking at his folder: green files are the ones he's marked interesting, blue files are the interesting files that have been successfully shared with the team, and the ones without colour are the ones of no interest.
Now, if you're like me, you'll probably want to use colour labels from shell scripts. Unfortunately, there is no easy way to do it.
You can use
xattr like this,
$ xattr -p com.apple.FinderInfo <filename> 00 00 00 00 00 00 00 00 00 0C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
The 10th bit is the color label, where 0=none, 2=grey, 4=green, 6=purple, 8=blue, A=yellow, C=red, E=orange.
Note: It has come to my attention that other bits of this byte may also be set, without affecting the color tag. It seems that Finder is ANDing the byte with
But if you want to read and set the color tag of files and folders from within shell scripts, you can use Daniel Fairhead's finder_colors.py.
$ finder_colors.py myfile.txt myfile.txt red $ finder_colors.py blue myfile.txt myfile.txt blue
An easy way to get just the color:
finder_colors.py myfile.txt | cut -f 2
Sample bash script:
for f in * ; do color=`finder_colors.py $f 2>/dev/null | cut -f 2` if [ "$color" = "red" ]; then # do something with "red" file echo Found a red one! $f fi done