Arranging Desktop Icons

I wrote a small AppleScript script (?!) that cleans up the desktop icons of users that I run on the machines that I administer. The script creates a folder on the desktop and moves all the items (except for the File Server and itself) into that folder.

What I want my script to do is arrange the icons after it moves the files around. I tried the clean up command but could not get it to work. Even when I tried to record my actions on Script Editor and tried to re-run that thing, it would give me an error.

What is the correct and tested way to reorganize the desktop icons using AppleScript?

Thanks a lot for your help in advance!


have you tried “Arrange By.”


What I did try was

clean up window of desktop

and similar. The problem is it could not understand things like desktop or window of desktop.

What can I do to do get hold of the desktop window?

“tell application “Finder” to clean up” (a verb belonging to the Finder) only applies to an open window in icon view. The desktop display is not a window, but I’m not sure what it is.

Googling around I see several shareware apps for doing this in XP, but none for OS X. That stuff is all stored in the .ds_store executable which isn’t human readable.


I guess it’s not possible to script the arrangement of the icons on desktop directly.
In a script I’m using this GUI equivalent

tell application "Finder" to activate
tell application "System Events"
	tell process "Finder" to keystroke "4" using {control down, command down}
end tell

If you want to read about .DS_Store files see this article