Apple OSX Cruft Removal

I am obsessive about the organization of the files on my computer. Apple does not understand my organizational system, and I do not understand theirs. On the operating system drive, I leave the files how OSX put them. On my removable media, Apple should leave things as I put them. So I wrote two files to allow me to “umount” properly.

To make this work by just typing “umount /Volume/<VolumeName>”, I added “export PATH=~/bin:${PATH}” to my “~/.profile” and put the following files in “~/bin”.

If you read this far and do not know what I am referring to, you probably should stop reading here and find something else to do. Otherwise, let me know if you have any problems with this technique, or a better solution.

--- Begin ~/bin/umount ---
#!/bin/sh
# File: umount
# Author: Brian Lindsay
# Purpose: umount a volume from OSX (calling uncruft first).
# Usage: umount /Volume/

uncruft "${@}"
diskutil unmount "${@}"
--- End ~/bin/umount ---
--- Begin ~/bin/uncruft ---
#!/bin/sh
# File: uncruft
# Author: Brian Lindsay
# Purpose: Remove OSX cruft from a filesystem volume.
# Usage: uncruft /Volume/

# MCP
main(){
	clean "${@}"
}

# All known sources of cruft in OSX
osxcruft(){
	#Files
	#echo "._AppleDouble"
	echo "._*"
	echo ".DS_Store"
	echo ".VolumeIcon.icns"
	#Folders
	echo ".fseventsd"
	echo ".Spotlight-V100"
	echo ".TemporaryItems"
	echo ".Trashes"
}

# Forcibly remove cruft
clean(){
	cd "${@}"
	osxcruft | while read cruft; do
		rm -rf ${cruft}
	done
}

# Run program.
main "${@}"
--- End ~/bin/uncruft ---

Post a comment.