Automatically remove clutter from the desktop
John writes:
I was wondering if there was a way for the Mac to automatically clear the desktop and put all the items into the documents folder when shutting down. I'm setting up a computer which has a lot of users and clutter on the desktop is an issue. Thanks.
This is a great example of when AppleScript is really useful for automating simple tasks like moving files around. In fact, you can do it with a script that is only three lines long.
Start by opening up AppleScript Editor, located in the Utilities folder inside the Applications folder. If you don't have Snow Leopard, the latest version of Mac OS X, this might be called Script Editor and instead is located in the AppleScript folder in the Applications folder. In the window that appears, paste the following three lines:
tell application "Finder" move items of (path to desktop folder) to folder (path to documents folder) end tell
If you click Run, you should see all the items on your desktop move into your Documents folder. Choose Save As from the File menu, give the script a name like cleardesktop and change the File Format to Application. Save it somewhere safe where someone won't accidentally delete it. I have a folder inside my Documents folder called Scripts where I keep all my AppleScripts. Other people choose to store their scripts in the Scripts folder in the Library folder, because Apple has already put some ready made ones in there.
The next step is to make it run every time you shut down your Mac. This is pretty tricky to do, and involves using a lot of Terminal commands. Instead, a much easier way is to make the script run when you log in, which will essentially do the same thing. Just go to System Preferences, and click on the Accounts section. Choose your account from the list on the left, and then click on the Login Items tab. You can now either click the plus (+) button and locate your script, or just drag the script from a Finder window into the list.
Now, whenever you turn on your computer, all the clutter left over from the previous user will be automatically moved into the Documents folder.
The above script is just about as basic as you can get. Here’s an idea for a more complicated version. Instead of just dumping everything in your documents folder, it instead creates a folder in there with a name that includes todays date ( e.g. “Desktop 13/01/2010” ) and puts the items in this folder instead.
set foldername to ("Desktop " & short date string of (current date)) set docsfolder to (path to documents folder) as string tell application "Finder" if not (exists folder (docsfolder & foldername)) then make new folder at docsfolder with properties {name:foldername} end if move items of (path to desktop folder) to folder (docsfolder & foldername) end tell
Alternatively, the following script checks the file extension of all the files on the desktop, and sorts them into the Movies, Pictures, Applications and Documents folders depending on what they are. If you are feeling adventurous, you can modify the script to include your own folders and file extensions.
tell application "Finder" set desktopFolder to (path to desktop folder) set musicFolder to (path to music folder) set appsFolder to (path to applications folder) set picsFolder to (path to pictures folder) set moviesFolder to (path to movies folder) set docsfolder to (path to documents folder) set musicExt to {".mp3", ".aac"} set appsExt to {".dmg", ".sit", ".app"} set picsExt to {".jpg", ".gif", ".tif", ".png", ".psd"} set moviesExt to {".avi", ".mpg", ".mov", ".m4v"} set docsExt to {".pdf", ".txt", ".doc", ".xls", ".key", ".pages"} set allFiles to files of desktopFolder repeat with theFile in allFiles copy name of theFile as string to FileName repeat with ext in musicExt if FileName ends with ext then move theFile to musicFolder end if end repeat repeat with ext in appsExt if FileName ends with ext then move theFile to appsFolder end if end repeat repeat with ext in picsExt if FileName ends with ext then move theFile to picsFolder end if end repeat repeat with ext in docsExt if FileName ends with ext then move theFile to docsfolder end if end repeat repeat with ext in moviesExt if FileName ends with ext then move theFile to moviesFolder end if end repeat end repeat end tell