Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I'd like to have something that I can run from Alfred or the command-line that can run "clean up desktop".

What is a command-line program or apple script that will cleanup the desktop?

Preferably there would be an option to do it by name or some other system (i.e., at least all the options that are available when right clicking the desktop).

share|improve this question
    
I was going to suggest an osascript like tell application "Finder" to clean up the desktop but ran into problems with the clean up verb with the desktop object... apparently it only works on windows :(. Here's a bunch of suggestions for scripts that could probably be turned into osascript arguments discussions.apple.com/thread/416256?start=0&tstart=0 –  nine9ths Nov 16 '12 at 4:28
add comment

2 Answers

up vote 3 down vote accepted

You have to use clean up window of desktop instead of clean up the desktop.

tell application "Finder" to clean up window of desktop by name
share|improve this answer
1  
Putting that together so it's useable from the commandline you'd want osascript -e 'tell application "Finder" to clean up window of desktop by name' –  nine9ths Nov 16 '12 at 5:38
add comment

Using @Lauri Ranta's answer as a starting point, I put together this Applescript for Alfred:

on alfred_script(q)
set q to "" & q
if q is "kind" then
    tell application "Finder" to clean up window of desktop by kind
else if q is "cdate" then
    tell application "Finder" to clean up window of desktop by creation date
else if q is "mdate" then
    tell application "Finder" to clean up window of desktop by modification date
else if q is "size" then
    tell application "Finder" to clean up window of desktop by physical size
else if q is "label" then
    tell application "Finder" to clean up window of desktop by label index
else
    tell application "Finder" to clean up window of desktop by name
end if
end alfred_script

You can see the different parameters to change the order that you want in the script (and change them to something that makes better sense to you if you want).

To use it, open Alfred's Preferences -> Extensions and click the + button in the lower left. Choose AppleScript and enter a name for it. (I called mine 'Clean up desktop'.) Write a Title and a Keyword for the script, and then paste the code into the AppleScript field. Click Save and you should be good to go!

If you're using Alfred 2: open Alfred's Preferences -> Workflows and click the + button in the lower left. Choose Templates -> Essentials -> Keyword to AppleScript. Double-click the keyword node and set the keyword you want (I chose cdesk), Title and Subtext (here I listed the possible arguments: kind, cdate, mdate, size, label). Save the results and then edit the Run NSAppleScript node and paste the code and save.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.