前面のウインドウを最大化する AppleScript

前面のウインドウを最大化する AppleScript です。スクリプトメニューなどから実行してください。GUI スクリプティングを使っているので、ほとんどのアプリケーションのウインドウを最大化できるはず。Dock の位置やサイズも判断しているよ。



property FrontAccess : module
property GUIScriptingChecker : module
property loader : boot (module loader) for me

on run
on error msg number errno
if errno is not -128 then
display alert msg message "Error Number : " & errno
end if
end try
end run

on |main|()
--activate application "Finder"
--activate application "mi"
if not do() of GUIScriptingChecker then
end if

--set front_window to (make FrontAccess)'s document_window()
set front_window to (make FrontAccess)'s main_window()

tell application "System Events"
tell application process "Dock"
tell UI element 1
set dock_position to position
set dock_orientation to orientation
set dock_size to value of attribute "AXSize"
end tell
end tell
end tell

tell application "Finder"
set screen_size to bounds of the window of the desktop
end tell
set item 2 of screen_size to 22
if dock_orientation is "AXHorizontalOrientation" then
set item 4 of screen_size to item 2 of dock_position
if item 1 of dock_position is 0 then
set item 1 of screen_size to item 1 of dock_size
set item 3 of screen_size to item 1 of dock_position
end if
end if

tell application "System Events"
set position of front_window to items 1 thru 2 of screen_size
set size of front_window to {(item 3 of screen_size) - (item 1 of screen_size), (item 4 of screen_size) - (item 2 of screen_size)}
end tell
end |main|