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

Remove everything from the desktop Desktop
I like to keep my desktop clean, so I wrote a very short AppleScript that will remove all items, and eject all non-local disks, from the desktop. I use this after I have downloaded a bunch of programs to my desktop that I no longer need -- usually because they have been installed into my apps folder.

I call the program "Finder CleanDesk." I call the AppleScript via Butler (Command-space then 'fc'). It will then send files on your desktop to the trash, and eject non-local disk images. It will not send your hard drive, iDisk, etc. to the trash -- which is a good thing. You can modify the script to only remove files or only eject non-local disk images. Note that you will want to replace Macintosh HD with the name of your hard drive, and replace username with your short username.

robg adds: This script is quite dangerous. As explained, it moves everything on your desktop to the trash. It does not empty the trash, so you won't lose anything immediately. It does serve a purpose, especially for those who like super-clean desktops ... but be aware of what it does before you use it!
tell application "Finder"
  move every item of alias "Macintosh HD:Users:username:Desktop:" to trash
  eject (every disk whose ejectable is true or not local volume is true)
end tell
[robg adds: Enter the script in Script Editor and save it somewhere you can easily find it. Butler, or one of many other tools, can be used to assign it to a global hotkey. You could also put it in your Scripts menu to make it just a bit harder to run, so as to cut down on accidental uses...]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[10,039 views]  

Remove everything from the desktop | 12 comments | Create New Account
Click here to return to the 'Remove everything from the desktop' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Junk instead of Trash
Authored by: googoo on Jan 07, '05 10:24:13AM

If you are leery of trashing everything, you could move all the files on the desktop to another folder, like ~/Documents/Junk/ or something.

-Mark



[ Reply to This | # ]
Junk instead of Trash
Authored by: KingDoom on Jan 07, '05 01:46:19PM

This is a good idea; I did not think of this.



[ Reply to This | # ]
Junk instead of Trash
Authored by: Oops on Jan 08, '05 06:23:18AM
But he would not be KingDoom to the files if it he did not send them to the Trash. :-)

[ Reply to This | # ]
Remove everything from the desktop
Authored by: jonn8n on Jan 07, '05 12:05:51PM
Here's how I'd modify the script to allow it run for any user and also ensure some safety nets:
property desktop_stuff : "Desktop Stuff"
tell application "Finder"
  activate
  try
    set the_items to items of desktop
    set the_button to button returned of (display dialog 
      "Should I move the items on your Desktop to the Trash or to the \"" & 
      desktop_stuff & "&\" folder?" buttons {"Cancel", "Trash", desktop_stuff} 
      default button 3 with icon 1)
    if the_button = "Trash" then
      move the_items to trash
    else if the_button = desktop_stuff then
      try
        set target_folder to (path to documents folder as Unicode text) & 
          desktop_stuff & ":"
        get target_folder as alias
      on error
        make new folder at (path to documents folder) with properties 
          {name:desktop_stuff}
      end try
      move the_items to target_folder as alias
    end if
  end try
  try
    set the_disks to (disks whose ejectable = true or not local volume = true)
    set the_button to button returned of (display dialog 
      "Should I remove ejectable, non-local disks?" buttons {"No", "Yes"} 
      default button 2 with icon 1)
    if the_button = "Yes" then eject the_disks
  end try
end tell
Jon

[robg adds: I edited the script to reduce its width, but didn't change any of its content.]

[ Reply to This | # ]
Remove everything from the desktop
Authored by: twistedsun on Jan 07, '05 02:02:07PM

why not use deskshade? the new version is great! http://macrabbit.com/deskshade/



[ Reply to This | # ]
Remove everything from the desktop
Authored by: killerbass on Jan 08, '05 04:49:37PM

There's a bug in your code...

If you look at my slightly modified code, I changed the fifth line -- by adding "whose kind in not volume". Without that line, the script trips up when trying to move the files...

I also added "folder" in the move line, as I have had scripts mess up without it.

Hope this helps,
Tom

property desktop_stuff : "Desktop Stuff"
tell application "Finder"
activate
try
set the_items to items of desktop whose kind is not "volume"
set the_button to button returned of (display dialog
"Should I move the items on your Desktop to the Trash or to the \"" &
desktop_stuff & "\" folder?" buttons {"Cancel", "Trash", desktop_stuff}
default button 3 with icon 1)
if the_button = "Trash" then
move the_items to trash
else if the_button = desktop_stuff then
try
set target_folder to (path to documents folder as Unicode text) &
desktop_stuff & ":"
get target_folder as alias
on error
make new folder at (path to documents folder) with properties
{name:desktop_stuff}
end try
move the_items to folder target_folder
end if
end try
try
set the_disks to (disks whose ejectable = true or not local volume = true)
set the_button to button returned of (display dialog
"Should I remove ejectable, non-local disks?" buttons {"No", "Yes"}
default button 2 with icon 1)
if the_button = "Yes" then eject the_disks
end try
end tell



[ Reply to This | # ]
Hard drive name not necessary
Authored by: john1620b on Jan 07, '05 02:18:44PM

I've written a similar script for cleaning the desktops in a computer lab setting, and you don't need to put the hard drive name in the file path. This makes things a whole lot easier when administering multiple computers with different hard drive names.



[ Reply to This | # ]
Remove everything from the desktop
Authored by: darkhalf on Jan 07, '05 03:00:16PM

The finder preferences has options to show what's on the desktop apart from files in the Desktop folder; you can have mounted network filesystems and media without dedicating an icon.

With all of these options disabled, "cleaning" this is as simple as hitting command-a followed by command-delete after focusing onto the desktop.

I personally never run with any icons on the desktop (and sometimes don't even run the Finder to make it unclickable).



[ Reply to This | # ]
Remove everything from the desktop
Authored by: DavidRavenMoon on Jan 07, '05 03:13:30PM

I made a downloads folder and have downloads saved there. Keeps the desktop clean!

---
G4/466, 1 GB, Mac OS X 10.3.7



[ Reply to This | # ]
Alias Your Downloads Folder
Authored by: drdarrow on Jan 07, '05 06:49:23PM

I made a Downloads folder on another smaller drive on the other internal [66mhz] bus (slower), placed an ailas of it on my desktop and pointed all pertinant apps to the alias as "the place to dump downloads"

My desktop lists all volumes (which, of course, I can hide) and a downloads "folder" that is really an alias to a slower drive (which is plenty fast enough to store downloads). Otherwise, my desktop is clean.



[ Reply to This | # ]
For just the optical drive?
Authored by: genericuser on Jan 07, '05 06:40:04PM

How would one modify this script to eject discs only in the internal optical drive? Thanks!

-Geoff

---
Bugmenot public account



[ Reply to This | # ]
For just the optical drive?
Authored by: kandrewnet on Sep 24, '05 07:48:06PM
I modified the above code to do this. It will eject any optical drives, zip drives, etc.

tell application "Finder"
	activate
	try
		set the_disks to (disks whose ejectable = true or not local volume = false)
		eject the_disks
	end try
end tell


[ Reply to This | # ]