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.