Delete All .DS_Store Files from Your home Folder Automatically¶
Deleting .DS_Store files automatically is a pain in the ass on macOS, because cronjob aren't functioning properly, and most home folders are protected, this requires effectively making a "full" .app, giving it full disk access, then running that .app on a schedule.
Open Automator¶
- Open Automator
- Click New Document
- Select Application (not Workflow) → Choose
Add a “Run Shell Script” Action¶
- In the search box, type “Run Shell Script”
- Drag Run Shell Script into the workflow area
- In the shell script box, enter:
Note: macOS's find has a bug when going through a lot of files (which will happen in your home folder), where it will randomly trigger an error window containing find: fts_read: Invalid argument. Adding 2>/dev/null at the end of the script might fix it, but otherwise as a solution, you can instead install the GNU version of find from brew and edit the shell script by replacing /usr/bin/find with /opt/homebrew/bin/gfind
Save the Automator App¶
- Go to File → Save
- Name it something like:
DeleteDSStore.app
- Save it somewhere like
/Applications/Utilities/
Grant Full Disk Access¶
- Open System Settings → Privacy & Security → Full Disk Access
- Click + → Add your DeleteDSStore.app
- Make sure it is toggled ON
Test it (optional)¶
- Double-click the app → It should silently delete
.DS_Storefiles, including in Documents/Desktop. - You can check by running:
If nothing shows, it worked.
Make it Run Automatically¶
Create a macOS LaunchAgent:
~/Library/LaunchAgents/com.delete.dsstore.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key><string>com.delete.dsstore</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/open</string>
<string>-a</string>
<string>/Applications/Utilities/DeleteDSStore.app</string>
</array>
<key>StartInterval</key><integer>300</integer>
<key>StandardErrorPath</key>
<string>/dev/null</string>
<key>StandardOutPath</key>
<string>/dev/null</string>
</dict>
</plist>
The value of StartInterval set to 300 means it will run every 300 seconds, if you want it to run less (or more) often change this number.
Make the permission correct:
chown $(whoami) ~/Library/LaunchAgents/com.delete.dsstore.plist
chmod 644 ~/Library/LaunchAgents/com.delete.dsstore.plist
Make it actually trigger:
Test that It's Running Properly¶
- Wait a bit 5-15 minutes
- Check that all the DS_Store files are gone:
If You Ever Want to Stop it¶
If you ever want to stop it:
Note if it Doesn't Work in Your Protected Folders¶
Automator Apps Need Full Disk Access — Every Time You Edit Them
On recent macOS version, Automator apps don’t retain the permissions you gave them once you edit or rebuild them. macOS treats each new build of the app as a different app, so you must remove and re‑add it in System Settings → Privacy & Security → Full Disk Access each time you change the app.
Fix:
- Delete it from Full Disk Access
- Add it again
- Restart the Mac
- Then test the app
Simply toggling it on sometimes doesn’t take effect until you reboot.
Source¶
- Me, TheFrenchGhosty, since DS_Store files are a pain anytime I use macOS
- An LLM (sorry, I didn't even know making stuff in Automator could be that powerful before the LLM told me) that I did babysit heavily, all of what it gave me was double/triple checked by me, and what is written was almost fully written by me (or fully edited by me)