Home‎ > ‎Mac Stuff‎ > ‎

No Dots

I have an iRiver MP3 player, a deck in my car that plays MP3s from a USB stick, a stereo at work that plays MP3s from a USB stick, a PC that I play MP3s from an SD card, and a DVD player that plays DivX movies from a USB stick. Bottom line: I move a lot of MP3 and DivX files around. The one thing that all of these non-Apple environments have in common is that they are unfriendly to the various dot files that the Mac OS sprinkles around liberally. So I decided to craft myself a solution to eliminate these files easily.

The solution I came up with is probably over-engineered in some ways and under-engineered in other ways. It's kind of complicated, but hopefully not too complicated. Some basic proficiency with AppleScript, unix and the Terminal is assumed. If you're not comfortable with all of these, then this example is probably not for you.

The solution has three components:

  1. A shell script
  2. An AppleScript (that is launched from the Finder toolbar)
  3. A fail-safe file that protects from unintended mayhem

Let's start with the shell script. First you'll want a place to keep it. Being a long time unix user who crafts a lot of his own tools, I usually have my own bin folder inside my home folder. In other words I assume that ~/bin exists and this is where my shell script resides. If you want to put yours somewhere else, then you'll need to modify the AppleScript accordingly.

So, here's the shell script. You can use your favorite editor to cut and paste the following. I named the file nodots.sh.


if [ -e "!UnDotAble" ]
dot_clean -m --keep=mostrecent .
find . -depth -name "\.*" -exec rm -rf {} \;
echo "!UnDotAble file not found - dot files untouched"
exit 0

After saving this in ~/bin you will need to make it executable with the following command in a Terminal window and in the directory you saved the shell script:

chmod +x nodots.sh

A few notes about the script.

  • It won't run if it does NOT find a file named !UnDotAble in the directory where it is executed from. More on that later.
  • It uses Apple's dot_clean tool to merge the ._* files with their counterparts. Don't worry about what this means. Suffice it to say that this is better than merely blowing them away.
  • There will likely be some dot files left over - associated with the trash, spotlight, and other stuff so the find command will remove them.
  • Sometimes the find command gets confused about whether a particular file is still around and it generates a file-not-found error by trying to delete it again (it's rare and I've only ever seen this behavior in Mac OS X). I chose to ignore this (and all errors) and always return a non-error status with exit 0. The only possible consequence of this is that some peculiar dot file might not get removed for some peculiar reason and you won't know about it. I've never seen this happen... I'm just hypothesizing that it could happen... maybe.
  • Also, this whole solution evolved... and is still evolving. It started with the shell script, which is why it still has code to print an error message if it doesn't find the !UnDotAble file.

Now on to the AppleScript. You can cut and paste the following into an empty AppleScript. You will want to save this file as an application (I called it nodots without the .app extension) in HardDisk --> Library --> Scripts --> Finder Scripts (where HardDisk is your top level).

tell application "Finder"
set currentFolder to the target of Finder window 1 as text
set currentPath to (quoted form of POSIX path of currentFolder)
set junk to do shell script "cd " & currentPath & ";~/bin/nodots.sh &> /dev/null"
display dialog "Done..." buttons {"OK"} default button 1
end tell

This script finds the path from whence it was called and then runs nodots.sh in that directory. Most of the trickery is about finding the calling path. There are still some random messages that are occasionally returned by "do shell script", so as added precautions against unwanted messages, I set the result to a variable called "junk" which is promptly ignored and I pipe the stderr from the shell script to /dev/null... which unix geeks like to call the bit bucket.

You may want to add a custom icon at this point. Here's the one I use (I'm not much of an artist, but I think it gets the point across [no pun intended]):

Next drag the script/app to the toolbar of an open Finder window to install it (you may have to click the oval button in the top right hand corner of the window to toggle the toolbar). It should look something like this:

OK, one last step. On each volume (AKA disk or drive) that you want to be able to remove the dot files you need a small file... and when I say small, I mean 0 bytes. Here's how you can do this from the terminal. First, open a terminal window. Type "cd" followed by a space and then drag the icon for the volume you are interested in to the terminal window and hit return. This should make the top level of the drive your current working directory. Now type the following in the terminal window:

touch !UnDotAble

I use "Get Info" to lock the file so I don't accidentally remove it when I'm moving files around. You can drag-copy the !UnDotAble file between disks, but it is ill-advised to leave copies lying around on disks where you don't want to accidentally remove dot files. If you simply must - bury it in an otherwise empty folder somewhere.

BTW, you will need to either quit the terminal or cd to another directory before you can eject the volume. You will get a disk-in-use error otherwise.

To use, just move the files you want to your removable drive, open that drive so that you see a window similar to above and click on the nodots icon. Now you can eject your disk dot file free.

Note: As soon as you plug your disk back into a Mac some hidden Trash and Spotlight files will be re-created.

Joey Blades,
Feb 8, 2011, 10:01 AM
Joey Blades,
Feb 8, 2011, 10:01 AM