FINDER: Controlling Arrangement of icons

The following script arranges the icons of the chosen folder’s window, and of all its subfolders’s windows.


set rootFolder to choose folder

tell application "Finder"
	open rootFolder
	set theFolders to {folder rootFolder} & (every folder of entire contents of rootFolder)
	
	repeat with aFolder in theFolders
		set containerWindow to container window of aFolder
		tell containerWindow to tell its icon view options to set arrangement to snap to grid
	end repeat
	
	close container window of rootFolder -- close and open window again, to see changes
	open rootFolder
end tell