How to prevent Mac OS X creating .DS_Store files on non Mac (HFS) Volumes?

17

12

Is there a way to prevent Mac OS X creating .DS_Store and other hidden meta-files on foreign volumes like NTFS and FAT? I share an NTFS partition with data like Thunderird & Firefox's profiles and apache's DocumentRoot, between Mac OS X and Windows, which is very handy. I don't mind if Mac OS X is not capable of indexing or otherwise doing the neat things those metafiles are for.

Note: It's not shared over a network, both operating systems and the shared partition coexist on the same disk, on the same machine.

Petruza

Posted 2009-09-28T12:56:35.907

Reputation: 3 043

Answers

19

If you are sharing the NTFS partition over a network, using SMB or some such, you can turn it off.

defaults write com.apple.desktopservices DSDontWriteNetworkStores true

Apple tech bulletin "How to prevent .DS_Store file creation over network connections". I have not verified that this still works with Snow Leopard.

Richard Hoskins

Posted 2009-09-28T12:56:35.907

Reputation: 10 260

I'm not sure that works unless they actually are on a network drive. – alex – 2009-09-28T13:23:21.870

@alex I think you're right. The OP hasn't said how he is sharing the NTFS partition. I'll edit my answer, but it may be flat out wrong. – Richard Hoskins – 2009-09-28T14:45:58.123

Nope, not over the network. One disk only, Mac OS in one partition, Windows on the other, and a NTFS partition for shared files. – Petruza – 2009-09-28T17:51:14.473

PS: Sorry, what does OP stand for? I know it refers to me, but don't know the meaning. – Petruza – 2009-09-28T17:53:28.447

1@Richard Hoskins: your answer refers to preventing the creation of .DS_Store files over the network. There's no way of stopping this if it's on the same drive. @sudo petrutza: OP means Original Poster (had no idea either) – alex – 2009-09-28T18:01:57.260

5

I use this I set it up once when I got annoyed with the same problem. This method make the system do it all automatically.

  1. Create a script called Remove_Hidden_Files.sh by opening terminal and for example cd ~/Documents and type touch Remove_Hidden_Files.sh

  2. Using vi create the script. In Terminal type vi Remove_Hidden_Files.sh

  3. Press "I" to get in to insert mode and type the following (Hint to get # press alt and 3)

    #!/bin/bash
    # Removing the hidden files from my drive using the find command. Change xxx to the name of your external volume or path you wish to run the command on.
    # the -mount will stop the find command going to other volumes other than specified.
    
    find -x /Volumes/(xxx) -mount -name '.DS_Store' | xargs rm -rf
    find -x /Volumes/(xxx) -mount -name '.Spotlight-V100' | xargs rm -rf
    find -x /Volumes/(xxx) -mount -name '.Trashes' | xargs rm -rf
    find -x /Volumes/(xxx) -mount -name '._.Trashes' | xargs rm -rf
    find -x /Volumes/(xxx) -mount -name '.fseventsd' | xargs rm -rf
    
  4. Press escape to get out of insert mode and hold shift and press :

  5. Type wq! and then press enter

  6. Make the script executable chmod 775 ~/Documents/Remove_Hidden_Files.sh

  7. Test this out to make sure it works. You can easily do this by opening terminal and type cd /Volumes/(xxx) press enter and then ls -la to list all the files and you should see a .DS_Store if not navigate with the finder to the volume and then repeat the command and you should see one there.

  8. Open another terminal by pressing command key and N

  9. Type cd ~/Documents

  10. Type sh Remove_Hidden_Files.sh

  11. Go to the other terminal window and check the .DS_Store files are removed.

  12. Create a launch daemon. This means to run automatically so you don't have to do anything.

    Best way is to download lingon

  13. Create a daemon for you user account and call it com.remove_hidden_files.Launchd

  14. In the command box type sh ~/Documents/Remove_Hidden_Files.sh

  15. You can either type in the path or browse to it /Volumes/(xxx)

  16. Reboot the machine and try it out

Note if you rename your external drive, use a different named drive or path you will need to change the script.

Tim Kimpton

Posted 2009-09-28T12:56:35.907

Reputation: 51

So this cleaning will happen when? when you log in? – LarsH – 2018-06-08T21:42:45.480

6I like how this answer became a vim tutorial. Haha – macek – 2010-10-08T18:46:47.533

You can add Mac logout scripts without paying for third party apps by using sudo defaults... http://seeskill.wordpress.com/2012/02/23/mac-os-x-login-and-logout-scripts-demystified/

– mcandre – 2012-10-16T23:04:45.210

4

I use BlueHarvest for this purpose:

https://zeroonetwenty.com/blueharvest/

Works across all volumes and not just network shares as per Apple's solution.

Asinine Monkey

Posted 2009-09-28T12:56:35.907

Reputation: 899

FYI, BlueHarvest is a Mac program that costs $15 US for 3 computers (more $ for more computers), and has a "30 day free trial" – Xen2050 – 2017-03-08T20:16:08.787

The BlueHarvest web site linked above is unresponsive at the moment, which would appear to mean that support is unavailable. However the app is in the App Store. – LarsH – 2018-06-08T18:19:08.457

I've updated the URL. – Asinine Monkey – 2018-10-24T13:19:30.807