Keep Desktop Clean By Name

Recorded on February 2nd, 2015

I try not to keep a lot on my desktop, but sometimes it’s hard to avoid. What is there I like to have tidy, which means that I am frequently doing Finder » Clean Up By » Name

The first problem is that this only works if there are no other Finder windows open. Plus, it’s annoying to have to keep doing this every time the Desktop changes.

Enter AppleScript.

Thanks to this post on AskDifferent I found that the AppleScript command I wanted was:

    tell application "Finder" to clean up window of desktop by name

or in shell script format:

    osascript -e 'tell application "Finder" to clean up window of desktop by name'

that worked just fine. Now I just needed a way to do it automatically whenever the Desktop changed. I could use Hazel for this, but for simple folder monitoring and triggering, I prefer launchd:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
    <plist version="1.0">
            <string>tell application "Finder" to clean up window of desktop by name</string>

Translation: “Any time the /Users/luomat/Desktop/ folder changes, run osascript -e 'tell application "Finder" to clean up window of desktop by name'

Obviously you’ll need to change <string>/Users/luomat/Desktop</string> to the proper path for your $HOME.

To Install

  1. Download gist from GitHub
  2. Change /Users/luomat/ to whatever your $HOME directory is
  3. Move file to ~/Library/LaunchAgents/ (you can use whatever name you like, just be sure it ends with .plist)
  4. To activate it, run this in Terminal:

    launchctl load ~/Library/LaunchAgents/

To Uninstall:

In Terminal:

    launchctl unload ~/Library/LaunchAgents/

    mv ~/Library/LaunchAgents/ ~/.Trash/

The first line disables it in launchd and the second moves the plist to the trash folder so it won’t be used in the future.


Wondering why I called it instead of com.tjluoma.cleandesktop.plist? I’ll explain that in another post.