Setting "by Name" in Finder desktop window

I would like to be able to arrange the Finder desktop by name in a script. I can’t seem to be able to do this and the searching I have done has come up empty. I managed to put together this script which looked nice to me but when saved as an app it gives errors. Can someone help me out in OS 10.3?

tell application “Finder”
set arrangement of icon view options of folder “Desktop” of home to arranged by name
end tell

Clue: “icon view options” is a property of a window, not of a folder.

If the Desktop is in the frontmost window, this would do the trick:

tell application “Finder”
set arrangement of icon view options of window 1 to arranged by name
end tell

To be sure you have the right window:

tell application “Finder”
set the target of the front window to desktop
set the current view of the front window to icon view
set arrangement of icon view options of front window to arranged by name
end tell

Thanks for your reply, but that didn’t work. I get an error:

Can’t set <> of window 1 of application “Finder” to <> of application “Finder”.

Any guidance here would be appreciated :smiley:

In the Finder reference for Finder window and desktop window:
list view options (list view options, r/o)
that means you can only read the setting, not modify it.

Hi,

there is no command in AppleScript which performs the “Arrange By Name” function.
I recommend to use GUI scripting to choose the appropriate menu entry.
In Leopard it’s just a keyboard shortcut


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

In Panther you must probably select the menu item, something like


activate application "Finder"
tell application "System Events"
	tell process "Finder"
		pick menu item "Name" of menu 1 of menu item "Arrange By" of menu 1 of menu bar item "View" of menu bar 1
	end tell
end tell