Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.4: Use Automator to keep the desktop clean Desktop
Tiger only hintIt happens to the best of us: Desktop clutter. Try as we might, we always end up with all sorts of files on our beautiful desktop, and if you're anything like me [ie: retentive], it irks you, but you live with it until you can no longer see any remnants of your wallpaper. Then you must finally go through the arduous process of manually filing all that clutter. No more!

Now I know there are lots of ways to keep desktop clutter to a minimum, like changing default download folders, etc. However, I didn't want to sacrifice the convenience of working with archives, files, and such on the desktop in the short run. Instead, I created an Automator workflow (my first such endeavour) to automatically purge my desktop and file that mess for me, and it does the job very well!

This is what I did, you can obviously ammend it to suit your needs...

The objective is to take all the documents I have saved on the desktop for whatever reason, and file them away in logical groupings. Here's an example of the portion of my action that does the filing for my work-related documents. (Note that the following examples show the Auomator Library name, then the action within that library, and then any options for that action.)
  1. Spotlight - Find Finder Items:
    • Where: 'Desktop'
    • Whose 'Name' 'Contains' 'Work'
  2. Finder - Move Finder Items:
    • To 'Work,' where 'Work' is the name of a folder in my Documents folder
This duo basically makes use of file tags I use when saving documents. I put Work at the start of the filenames of all my files that relate to work. The above lines will then automatically put those files in a folder called Work in my Documents folder. My flow contains several pairings like this (ie: School for School) to sort all sorts of documents. Sit down and think of a tagging system that makes sense for you, create the relevant folders in your Documents folder, and then use variants of the above pairing to automatically file your documents away.

Next I want to store any media files in the right places:
  1. Finder - Find Finder Items:
    • Where 'Desktop'
    • Whose 'Kind' 'Is' 'Audio'
  2. Finder - Move Finder Items:
    • To 'Music'
Here, 'Music' is the name of the default Music folder, or whatever folder you keep your music in. You can duplicate that pairing for any kind of media by changing the 'Kind' to Movie or Image, and then changing the destination folder.

If you take a lot of screenshots, you might want to do something a little different to filter images on your desktop. Because screenshots> end up on the desktop as nothing more than 'Picture 1,' 'Picture 2,' and so on, I use this group of actions to automatically rename those images to something a bit more descriptive before they get filed:
  1. Finder - Find Finder Items:
    • Where: 'Desktop'
    • Whose 'Kind' 'Is' 'Image'
  2. Finder - Rename Finder Items:
    • 'Replace Text'
    • Find 'Picture'
    • Replace 'Screenshot taken'
  3. Finder - Rename Finder Items:
    • Add Date or Time
    • Date/Time 'Created'
    • Where 'After name'
    • Seperator 'Dash'
    • Format 'Month Day Year'
    • Separator 'Forward Slash'
  4. Rename Finder Items:
    • Add Date or Time
    • Date/Time 'Created'
    • Where 'After name'
    • Separator 'Dash'
    • Format 'Hour Minute Second'
    • Separator 'Forward Slash'
  5. Move Finder Items:
    • To 'Photos'
This group of actions turns that screenshot that was named Picture 1 into one called Screenshot taken 1 M/D/Y-H/M/S. That is a lot of data to add to a file, I know, but the reason is that Automator will not move files if they are identical in filename to other files in the destination folder (they will get marooned on the desktop). Thus, by adding the creation time right to the second, you ensure that you will never create the exact same filename twice for your screenshots. The only thing this can't do is get rid of the number after "Picture," because it will vary from screenshot to screenshot.

This also works well as a filter for non-screenshot images, too, with the caveat (of course) that it will remove any instance of the word "Picture" from their filenames, and will add all that time and date data to them. If you don't use screenshots that often and don't want all that data added to your image files, just stick to a regular media filter as described above for Audio files.

Next I wanted my filter to move all of my disk images and other archives that littered my desktop and then move them to a folder called Installation Files in my Documents folder. (You can just as easily move them to the trash if you are not a packrat like me.) To do that, I used these steps in my workflow:
  1. Find Finder Items:
    • Where 'Desktop'
    • Whose 'Extension' 'Is equal to' 'dmg'
  2. Move Finder Items:
    • To 'Install Files' (or change it to Trash if you want to chuck them)
I then copied and pasted that pair of commands over and over again, to include all the common archive files like zip, sit, bin, sitx, hqx, iso and exe (if you run apps in VPC). There are others, but I found these covered most bases. Note that Automator allows you to put multiple criteria in each action, instead of duplicating the above pair and changing the extension. For whatever reason, I found this to be unreliable, and it only worked well when each extension got its own action [selfish extensions perhaps?]. I also added a pair like this for the widget extension so that Yahoo Widget (Konfabulator) downloads could be sent to their special Widget folder. However, I had to change it to 'extension' 'contains' 'wid' to make it work; using 'is equal to' and the full 'widget' extension left stragglers. Finally, I included "app" as an extension to be moved to install files, but you may not want to do that if you purposely store applications on your desktop (I don't).

And that is the gist of it. You can improvise, adding filters to send your URL links t your bookmarks folder, etc., but if you are new to Automator (as I was just two days ago), this explanation should give you the background to make your own Workflow perfect for tidying up your desktop. But there is one final step: How do you run this thing once it is done? There are two options I use. First, save the file as a regular workflow, then:
  1. Go to Save As Plug-In and from the pop up menu in the Save dialog, choose iCal from the list of apps. Once you do that, iCal will automatically open with a new recurring event that you can set the parameters for. You could, for instance, clean your desktop every night at 1am, or once a year in the spring if you prefer. The best part about this is that you don't have to have either Automator or iCal running for this automation to work. At the set time, the workflow will run and you will see its progress in the menu bar and, tada, your desktop is clear!

  2. I also wanted a way to manually run the workflow without having to open up Automator, and I wanted to be able to run it from an icon in the dock. So I went to: Save as Plug-in, and chose Finder from the pop-up menu; I called mine DeskTidy. To find the saved workflow, I just typed DeskTidy into Spotlight, and when it came up, I Command-clicked it, then dragged it from its folder onto the desktop. I then changed the icon to an image of nice clean Aqua desktop (to replace the default Robot icon). Since workflows are treated as applications, I was then able to drag it to the dock. Now if I don't want to wait for the designated iCal event, I can clear my desktop manually with a simple trip to the Dock.
Any suggestions for improvements are certainly welcome- like I said this is my first automator workflow ever!

[robg adds: I haven't tested this one...]
  • Currently 2.80 / 5
  You rated: 2 / 5 (5 votes cast)

10.4: Use Automator to keep the desktop clean | 11 comments | Create New Account
Click here to return to the '10.4: Use Automator to keep the desktop clean' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Use Automator to keep the desktop clean
Authored by: BlackPenguin on Feb 06, '06 08:33:05AM

I did something like this a while ago. It's great for cleaning up in general. I also added parts for sorting and filing text clippings and web locations, as I tend to accumulate many of those.

I like having my desktop as a temporary repository for stuff I'm working on (like my real desktop), so I use the script/workflow a bit differently. I have mine set up as a Folder Action plugin, and have it attached to a folder called "Sorting Bin". I leave an alias of that folder on my desktop. Whenever I'm tired of the mess, I drag everything to the bin, and the workflow fires up and sorts what it can. Everything it recognizes gets filed away, and anything else gets left in the Sorting Bin for me to deal with later. Clean desktop!

-- Nick

[ Reply to This | # ]
10.4: Use Automator to keep the desktop clean
Authored by: jump420 on Feb 07, '06 06:40:29PM

I like this solution better. Could you break it down some more? I'm not too familiar with folder actions.

[ Reply to This | # ]
10.4: Use Automator to keep the desktop clean
Authored by: macsolve on Feb 06, '06 10:30:35AM

If you just want to keep the desktop clean and don't care about sorting the stuff, TinkerTool has a setting to disable the Desktop. The files remain in the Desktop folder, but the desktop itself remains nice and tidy no matter how much you fill it...

[ Reply to This | # ]
10.4: Use Automator to keep the desktop clean
Authored by: jayhawksean on Feb 06, '06 01:27:32PM

Word of caution. I just made 26 instructions and accidentally forgot to change "computer" to "Desktop" for the files with the extension .jpg. Needless to say, my iPhoto library of over 6000 photos is really, really messed up now (all the way back to Jan. 2002). Most of my images were jpgs and now appear to be missing (they were moved to my newly created folder). aauuugh!

This can't be undone from what I can tell. So, I think I'll start over with iPhoto. Hope you're more careful. I didn't realize things could go so badly over this. hmph!

[ Reply to This | # ]
10.4: Use Automator to keep the desktop clean
Authored by: digitol on Feb 06, '06 09:31:09PM

Hey Apple_Turnover, (jokes) How Dare you Call it WALLPAPER!!! HOW DARE YOU!!! :) :) "Wallpaper? Wallpaper, is for your house."" desktop background or desktop pictures are for Macs! :) Thanks for the tip! :)

[ Reply to This | # ]
10.4: Use Automator to keep the desktop clean
Authored by: osxpounder on Feb 07, '06 10:06:02AM

LOL, well, on my Mac, it's wallpaper. It's a nearly vertical surface with some imagery on it -- that's more like wallpaper than like my desk's top, which is almost never vertical -- in fact it remains horizontal, on a good day, quite unlike the so-called "Desktop" on my Mac. You know, the thing that holds my wallpaper?


[ Reply to This | # ]
10.4: Use PERL to keep the desktop clean
Authored by: shemp9999 on Feb 07, '06 08:13:05PM
long ago i wrote an applescript to clean my desktop. once os x came around, i rewrote it in perl. it is easily adaptable for cleaning out other directories, too.

it simply checks for the file type using the unix 'file' command, and if that is not found, it uses the chars after the last dot in the name. then it copies the files into sorted folders in the destination dir. if a file already exists, it is skipped and is reported back to the shell. it could use more work to sort better, but i almost always find the file i want in a couple of clicks.

#!/usr/bin/perl -w

my $input = "/Users/shemp9999/Desktop"; # directory to clean
my $output = "/Users/shemp9999/Deskcrap"; # directory to move files to

my $file;
my $inf;
my @xtmp;
my $xtmp;
my $base;
my $ext;

my $item;

foreach $file (`ls \"$input\"`){
  # set ignore list for aliases, etc...
  $in = "$input\/$file"; #input path with filename
  $inf = `file \"$in\"`;

  @item = split (/\:\s+/, $inf);

  $base = '';
  $ext = '';

  if ($file =~ /\./){ ## if there's a dot in the path/name
    @xtmp = split(/\./, $file);
    $ext = pop (@xtmp);
    foreach $xtmp (@xtmp){
      if ($base ne '') {$base .= '.' } ## restore dot
      $base .= $xtmp;
  }else{  ## if there's no dot extension 
    $base = $file;
  if ($ext ne ''){ 
    $dir = $ext;
    $dir = $item[1];
  $out = "$output\/$dir"; #input path with filename
  $outpath = "$out\/$file";

  unless (stat($outpath)){ ## if the file does not exist
    unless (stat($out)){ ## if the path does not exist
      `mkdir -p \"$out\"`;  ## make the path
    `mv \"$in\" \"$outpath\"`;## move the file
  }else{ ## file exists
    print "file $outpath exists, skipping\n";

[ Reply to This | # ]
10.4: Use PERL to keep the desktop clean
Authored by: DMCrimson on May 08, '06 04:35:57AM

Does not work... it moves all the files to destination directory, but does not sort them at all... Resukting error below

Use of uninitialized value in string ne at line 40.Use of uninitialized value in concatenation (.) or string at line 46.

[ Reply to This | # ]
10.4: Use Automator to keep the desktop clean
Authored by: Mac1985 on May 07, '06 01:45:11AM

I just don't understand why this won't work for me. I'll ask it to find files on the Desktop with the extension of .jpg, for instance.

I have two files with .jpg on the desktop. I have a folder on the desktop with a .jpg in it. Automator will ONLY find the .jpg in the folder.

It never sees any files directly on the Desktop. This seems to be very unique to the desktop folder and not any others.

[ Reply to This | # ]
10.4: Use Automator to keep the desktop clean
Authored by: tomhannen on Jul 11, '06 04:47:34AM

Aargh... Use with caution!

Automator goes recursivley into any folders on your desktop. So for example, if you have a folder full of animation frames in different subdirectories on your desktop, this will make Automator drop them all into one folder! And you can't undo it...

Anyone know of a way to make it only act on items on the desktop, not recursively into folders on the desktop?

Also - to the person having problems with JPG files - make sure you type "jpg" not ".jpg" into the extensions box. (ignore the quotation marks).

[ Reply to This | # ]
10.4: Use Automator to keep the desktop clean
Authored by: jklupfel on Jun 20, '12 03:14:44AM

Not sure if anyone is still responding here.

But, I tried setting up this workflow and tried moving whole folders from the desktop to another folder.
Does anyone know if that is at all possible?

[ Reply to This | # ]