Skip to main content
2 of 6
deleted 239 characters in body
dwightk
  • 7.7k
  • 14
  • 48
  • 71

I got this to work on Sierra 10.12.3 in Automator.

First, I made this version of the script: It functions the same way as freefly42's, just a different way of writing the same thing.

To translate for non-native bash speakers, what it says/does is: If you just run it with no command line arguments, it runs itself once for every folder in /Volumes. If it is run with a commandline argument, it tries to see if the argument is a directory, and if that directory contains a file named ".disable_osx_metadata" For each folder found under /Volumes, if the directory does not contain a file ".disable_osx_metadata" then nothing happens to that directory. (So, your main hd is always ignored, and so is any other drive that you don't manually set up.) Any directory that does have the file, the script deletes all the osx metadata and creates a few small new items which prevents anything else.

So, if you run it manually, it checks all attached drives. If you create a workflow in Automator, then Automator runs it just on one specific drive, whenever a drive is attached.

#!/bin/bash
x=.disable_osx_metadata
[[ "$1" ]] || exec find /Volumes -type d -maxdepth 1 -mindepth 1 -exec $0 {} \;
[[ -e "$1/$x" ]] || exit 0
mdutil -i off "$1"
rm -rf "$1"/.{,_.}{fseventsd,Spotlight-V*,Trashes}
mkdir "$1/.fseventsd"
touch "$1/.fseventsd/no_log" "$1/.Trashes" "$1/$x"

Save as "disable_osx_metadata", chmod 755, copy to /usr/local/bin .

$ cd Documents/disable_osx_metadata/
$ chmod 755 disable_osx_metadata
$ sudo cp disable_osx_metadata /usr/local/bin

Then open Automator, New, Folder Action

Then I found that even in Sierra 10.12.3 you CAN still add the /Volumes directory in Automator, by a non-obvious way.

Go to Finder, File, "Go To Folder...", manually write in "/Volumes" and hit Enter.

Now this shows you a window with your HD and usb drives, but no obvious "/Volumes" folder to click on. But the title bar says "/Volumes", and it appears at the bottom too.

You can drag the folder icon next to "/Volumes", either from the title bar or from the bottom, over to the Automator, and drop it on "Folder action receives files and folders added to:[______]"

Drag /Volumes from Finder Title Bar

Back in Automator: on the left, scroll down and drag "Get Folder Contents" to the right and drop it.

Then on the left again, scroll down and drag "Run Shell Script" to the right and drop it below "Get Folder Contents". Shell:[ /bin/bash ] Pass input:[ as arguments ] Then drag the script from /usr/local/bin onto the box under "Run Shell Script" so it says "/usr/local/bin/disable_osx_metadata"

File, save, disable_osx_metadata.workflow

Automator Folder Action Workflow

(This gets saved in: /Users/YOUR_NAME/Library/Workflows/Applications/Folder Actions If you save something wrong and want to delete it or save under a different name, I think you have to manually navigate to there in Finder to delete them)

Finally, for each new usb drive you want to protect, you have to create a file named ".disable_osx_metadata" in the root folder.

In Terminal: touch /Volumes/NO\ NAME/.disable_osx_metadata or just copy any file with Finder into the usb drive and rename it .disable_osx_metadata

That drive now gets cleaned each time you attach it from now on.

Not as clean as I'd like. You have to pollute the external drive with a few files, in order to tell the OS not to pollute it with a lot more. There is no way make the OS simply leave the thing alone and have no junk files that you didn't want on there.