Publishers of technology books, eBooks, and videos for creative people

Home > Blogs > Mac Productivity: Quick Scripts and Workflows - Clean Up Your Desktop with Your Voice

Mac Productivity: Quick Scripts and Workflows - Clean Up Your Desktop with Your Voice

By  Apr 12, 2012

Topics: Apple, Operating Systems, Productivity

I tend to keep a pretty uncluttered Desktop.  I typically have only a handful of active files there at any given time, which I promptly remove when I'm done working with them.  I strongly suspect, however, that I'm in the minority.  Often, I see people with hundreds or even thousands of files on their Desktop.  They truly work off of their Desktop, and this simply isn’t efficient.  Locating files on a cluttered Desktop requires scrolling through tons of irrelevant files, moving icons around, searching, and more.  Perhaps if Siri was on the Mac, she could help.  Wouldn’t it be great if you could verbally instruct your Mac to clean things up for you?  Well, with Speakable Items and AppleScript, you can.  Here's how.

1. Launch AppleScript Editor (in /Applications/Utilities)

2. Create a new script document and enter the following:

set theArchiveFolderName to "Desktop Archive"

tell application "Finder"

set theItems to every item of desktop where its name is not equal to theArchiveFolderName

if (folder theArchiveFolderName of desktop exists) then

set theArchiveFolder to folder theArchiveFolderName of desktop

else

set theArchiveFolder to make new folder at desktop with properties {name:theArchiveFolderName}

end if

set theDateFolderName to date string of (current date) & "-" & (time of (current date))

set theDateFolder to make new folder at theArchiveFolder with properties {name:theDateFolderName}

move theItems to theDateFolder

end tell

Here’s what the script above does.  First, it gets a list of items (files and folders) on your Desktop.  Next, it checks your Desktop for a folder named Desktop Archive.  If this folder doesn't exist, the script creates it.  Then, the script creates a subfolder in the Desktop Archive folder, named with the current date and the time since midnight (to keep the folder unique).  Finally, it moves all of the items on your Desktop into the newly created dated folder.


The Clean Up Desktop script, in AppleScript Editor

This is great, but how can you trigger it with your voice?  You do it by installing the script and enabling Speakable Items.

3. Choose File > Save As...

4. Save the script to your Desktop in Script format as Clean Up Desktop


Saving the Clean Up Desktop Script

5. Launch System Preferences

6. Click Speech

7. Click the Speech Recognition tab

8. Click the Commands tab


The speech recognition preferences window

9. Click the Open Speakable Items Folder button.  This brings the Finder back to the front, and opens the ~/Library/Speech/Speakable Items folder.

10. Move the Clean Up Desktop script into the Speakable Items folder.


The speakable items folder

11. Go back to System Preferences > Speech

12. Click the On radio button to enable Speakable Items


Enabling speakable items

13. Click on your Desktop


Running the script with a voice command

To trigger the script, press the Escape key and speak clearly "Clean Up Desktop".  If things go according to plan, the script runs, and your Desktop is cleaned up into a dated archive folder.  Now, you just have to get into the habit of running this regularly to keep the clutter clear.  Afraid you'll lose something?  No problem.  Just use Spotlight to search for it in your Desktop Archive folder.


A cleaned up dated archive folder

For more on AppleScript and Automator, check out my book  Automator for Mac OS X: Visual QuickStart Guide, as well as my video podcast series Mac Automation Made Simple.