Skip to content

Instantly share code, notes, and snippets.

@poutyface
Created October 2, 2011 06:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save poutyface/1257154 to your computer and use it in GitHub Desktop.
Resize window for Mac
-- これは何?
-- Mac OSXでウィンドウを左端、右端に移動するとディスプレイの半分のサイズにリサイズするAppleScriptだよ。
-- Windows7にはAeroスナップってデフォルトでかっちょいいのがあるんだって、Macにはないよ。
--
-- どうすればいいの?
-- [システム環境設定]-[ユニバーサルアクセス]-[補助装置にアクセスできるようにする]をチェックする
-- [アプリケーション]-[ユーティリティ]-[AppleScriptエディタ.app]を起動
-- これをコピー&ペースト
-- [ファイル]-[保存]
-- * ファイルフォーマットをアプリケーション
-- * オプション、実行後自動的に終了しないをチェック
-- アプリができるから、ダブルクリックで起動
--
-- 制限事項
-- 幾つかのアプリが諸事情で対応できないよ。FireFox, Chrome等
-- とりあえず、Safari, Emacsは動くよ
on idle
tell application "Finder"
set screen_bounds to bounds of window of desktop
end tell
tell application "System Events"
set apps to name of every process whose frontmost is true
set target to item 1 of apps
if target is "" then
return 1
end if
tell process target
try
-- set top_window to item 1 of (every window whose focused is true)
set top_window to front window
on error
return 1
end try
set ws to size of top_window
set wp to position of top_window
if item 1 of wp < -100 then
set position of top_window to {0, 0}
set size of top_window to {round ((item 3 of screen_bounds) / 2), item 4 of screen_bounds}
else if (((item 1 of wp) + (item 1 of ws)) > ((item 3 of screen_bounds) + 100)) then
set position of top_window to {round ((item 3 of screen_bounds) / 2), 0}
set size of top_window to {round ((item 3 of screen_bounds) / 2), item 4 of screen_bounds}
end if
end tell
end tell
return 1
end idle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment