Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm looking for a way to change the appearance of empty folders within finder in order to distinguish them from folders with contents.

Does anyone know of a way to do this, either through third party software, through the OS, or programmatically?

share|improve this question
    
The only way I could think of would be to go through all directories with a shell script, then coloring the folders depending on whether they're empty or not. This, however, won't work automatically, you'd have to trigger it. –  slhck Aug 1 '12 at 19:29
    
That could work - I'd just need the part of the script that identifies empty folders I guess. –  mheavers Aug 1 '12 at 19:31

2 Answers 2

up vote 2 down vote accepted

This simple script goes through all empty folders starting from, for example, ~/Desktop, and applying the color 7, for grey.

Change these values to your liking, e.g. the folder to ~/Documents to go through all your files in the Documents folder. The label colors start at 0 for none, and 7 is the highest number.

#!/bin/bash
label=7
start=~/Desktop
while IFS= read -d '' -r dir; do
    osascript -e "tell application \"Finder\" to set label index of alias POSIX file \"$dir\" to $label" > /dev/null
    echo "Applied label to $dir"
done < <(find $start -mindepth 1 -type d -empty -print0)

To run this script, open a terminal through Applications/Utilities/Terminal.app, and open a text editor like nano.

Paste the contents, and save it by entering CtrlO, then typing a name for the file. Press when done. Now make it executable with chmod +x recolor.sh, and run it by typing its name like ~/Documents/recolor.sh.

It will print the path of all folders it applied the label to, and exit once done. Note that this will not automatically identify any new empty folders you might create in the future, so you'll have to run this script again.

One could also replace the call to osascript with the label() function from this Stack Overflow answer.

share|improve this answer

The following solution is mostly bash (shell) scripting, but integrated with Automator to make it more convenient to use.

Open Automator and select to create a new Workflow. Add a Run Shell Script action, that receives input to stdin and the following script:

find "$@" -type d -empty

If you run that in Automator, all empty folders will be shown in the Results. To act on them, add e.g. a Move Finder Items To Trash action or a Label Finder Items action below that.

By making this an Automator workflow, you can repeatedly execute it conveniently, or even make it executable as a Service on selected files or folders (File » Convert To… » Service, or start by making it a Service). That way, if you want to clean up a specific folder and its contents, you can do that quite easily.

You can assign keyboard shortcuts in System Preferences » Keyboard » Keyboard Shortcuts » Services.

enter image description here

share|improve this answer
    
Me thinks I've made the shell script a bit too complicated... –  Daniel Beck Aug 1 '12 at 19:56
    
Haha, I was gonna say :P – but using Automator is probably nicer. Feel free to "steal" the shell script. –  slhck Aug 1 '12 at 19:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.