Escaping `.DS_Store`: The Unconventional Solution

Problem formulation

Over the years, countless macOS users are complaining about additional files automatically created by Finder called “.DS_Store”. The “.DS_Store” files become very annoying when:

  • You are working with people with different operating systems (Windows, Solaris, Arch Linux, etc.).
  • You are sharing directories with a very small size (typically less than 6 KB).
  • You are compressing files to share with others while the receivers do not know what the extra .DS_Store file does.
  • You are just using Finder to view the edited time or total size of a directory while it suddenly changes due to spawn of .DS_Store files.
  • You are synchronizing files with a cloud storage while most (over a thousand) fragmented files are called .DS_Store.
  • You are not willing to expose a directory tree (see ds_store_exp on GitHub).
  • More cases in Wikipedia: .DS_Store.

Therefore, a way to escape .DS_Store is crucial to the users.

Former works

There are several works trying to make macOS user directories clean. Many simple scripts to alleviate the problem.

Some users may use other file managers to avoid Finder.app so that Finder.app would not frequently create .DS_Store.

Hackers may love to directly hack Finder.app to thoroughly solve the problem. See projects like Odourless on GitHub.

However, it is complicated for normal users to handle the problem with the works above. They require users to grasp at least basic concepts of programming.

What this article introduces

Actually, there is an unconventional solution to this problem. Let’s inspect macOS directory trees by Terminal.app and tree command.

1
2
3
4
5
6
7
8
bash-3.2$ cd ~/Movies
bash-3.2$ tree -a
.
├── .DS_Store
└── .localized

1 directory, 2 files
bash-3.2$

User’s normal directories usually contain at least one .DS_Store.

However, there are many special directories used by macOS ended with specific name extensions. For example, Safari browser is located at /Applications/Safari.app and Safari.app is a directory instead of a single file. Multiple .DS_Store inside the special directories is inappropriate. So, a way to bypass or escape .DS_Store is to put users’ normal files inside a special directory and treat the directory as a daily workspace.

1
2
3
4
5
6
7
8
9
10
11
bash-3.2$ cd /System/Library/Extensions/exfat.kext/
bash-3.2$ tree
.
└── Contents
├── Info.plist
├── _CodeSignature
│   └── CodeResources
└── version.plist

3 directories, 3 files
bash-3.2$

See. No .DS_Store inside a *.kext directory!

Introducing Kext as workspace method.

  • Open Terminal.app on macOS.
  • Create a Kernel Extension (Kext) directory under your home directory. Input the following lines and execute them in the terminal.
1
2
cd ~
mkdir protected.kext
  • Since *.kext cannot be treated as plain folder in Finder.app, create a subdirectory inside the Kext directory. Input the following lines and execute them in the terminal.
1
2
3
cd protected.kext
mkdir workspace
open -R .
  • Drag the directory workspace to the (left) side panel of Finder so you can access it easily anytime.

Now enjoy your file management life without automatic spawn of .DS_Store inside workspace folder! If you are moving files from other paths to it, please remember to manually recursively remove all .DS_Store automatically created before.

After two years of use of this workaround on my own MacBook, I finally pluck up the courage to introduce this method to completely get away from .DS_Store for all subdirectories inside the workspace folder.

Drawbacks

No more additional file info fields (only available on macOS) should be appended in a file

Since the file .DS_Store is for Desktop Services Store, some additional information attached to the files will be no longer recommended. For example, in the workspace folder created as described above, you should not append any information as comments inside Finder’s Get Info window. (In fact, these comments are not readable for Windows users and cloud storages.) These comments are also called Spotlight Comments for older Mac users, if you do not understand what I mean.

More explanations needed for normal users

This article is written in a hurry. The writing style should be improved and many details need polishes. But it should be very helpful for the Mac users being annoyed by .DS_Store.

It is still a pity that for normal Mac users, the solution requires at least one first-time help from professional users, because of the steps using the terminal. But with the help of those who know how to correctly operate terminals and explain the actual usage of the workspace folder, the solution must make file management on macOS much less painful than before.

Trivia

  • See Wikipedia: AppleSingle and AppleDouble formats for similar concerns for the files started with ._ and directories called __MACOSX.
  • Use dot_clean -mnsv . to recursively clean the AppleDouble files (at current working directory in terminal).
  • Use find . -name ".DS_Store" -depth -print -exec rm {} \; to recursively delete .DS_Store (at current working directory in terminal).

Escaping `.DS_Store`: The Unconventional Solution
https://lucisurbe.pages.dev/2024/03/02/Escaping-DS-Store-The-Unconventional-Solution/
Author
Lucis Urbe
Posted on
March 2, 2024
Licensed under