Safari のウィンドウを並べる

Safariのウィンドウを三つ横に並べられないか、というTweetがあったのでAppleScriptを書いてみました。
修正版はこちら

try
	-- get screen size
	tell application "Finder"
		set theScreen to bounds of (window of desktop)
		set X to item 3 of theScreen
		set y to item 4 of theScreen
	end tell
	
	tell application "Safari"
		activate
		set {hidari, ue, migi, shita} to {0, 22, X / 3, y}
		set theCount to number of document
		repeat while theCount > 0
			set bounds of window theCount to {hidari, ue, migi, shita}
			set {hidari, ue, migi, shita} to {hidari + X / 3, ue, migi + X / 3, y}
			set theCount to theCount - 1
		end repeat
	end tell
	
on error the error_message number the error_number
	log ("Error: " & the error_number & ". " & the error_message)
end try

ウィンドウが4つ以上あるとおかしな動作になっちゃいますね。宿題にします。m(_ _)m