Safari のウィンドウを並べる 【修正版】

Safariのウィンドウを横にきれいに並べるAppleScriptを修正しました。

前エントリーではウィンドウ数を3つに限定していましたので4つ以上ウィンドウが開いていると挙動が不自然でした。そこで開いているウィンドウをすべて横に並べて見ることにしました。

ベッドに入ってすぐに思いついたのですけれど、明日できることは今日やらないをモットーにしているのでそのまま眠っちゃいましたが、すでに修正してくださった方がいらっしゃいました。
http://www.sara-mac.com/?p=9678 [MacBSの日常生活的日記]

開いているSafariのウィンドウが一つの時は画面いっぱいに広がりますし、ウィンドウが二つでも四つでもきれいに横に並びます。

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 S to number of document
		set {hidari, ue, migi, shita} to {0, 22, X / S, 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 / S, ue, migi + X / S, 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

ついでなので、ウィンドウを右下へ少しずつずらし重ねて並べるのも作ってみました。

try
	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 * 0.8, y * 0.9}
		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 + 22, ue + 24, migi + 22, shita + 24}
			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

ウィンドウの大きさは

set {hidari, ue, migi, shita} to {0, 22, X * 0.8, y * 0.9}

で設定しています。ディスプレイに対して幅を8割、高さを9割にしていますが、ここを書き換えてお好みのサイズにしてください。

ウィンドウをずらす量はここで変更してください。

set {hidari, ue, migi, shita} to {hidari + 22, ue + 24, migi + 22, shita + 24}

スクリプトの改編、再配布など自由です。