我一直在使用 Better Touch Tool 和 Right Zoom,以便能够将窗口最大化至全屏,并将窗口大小调整至屏幕中央或右上/左上四分之一。这些应用程序非常流畅。
我真正想要的是一种预定义一些窗口规格的方法,然后将其应用于窗口。例如,窗口可以是 1024 * 768,或者可以是距离屏幕每个边缘 300px。
我知道绿色按钮应该为窗口选择一个合适的大小,但它并不总是有效,而对于某些应用程序(例如 TextMate),我只是希望有一个我可以使用的预设大小/位置。
我可能可以以某种方式使用 applescript,但有时它似乎需要很长时间才能运行,因此为此使用本机应用程序会更酷。
有什么想法吗?
答案1
迪维
微风
最优布局
用于保存和恢复默认尺寸的 AppleScript
保存边界.scpt
try
set text item delimiters to space
tell application (path to frontmost application as text)
set b to (bounds of window 1) as text
set n to name
end tell
do shell script "a=" & quoted form of n & "
f=~/Notes/bounds.txt
touch \"$f\"
sed -i '' \"/^$a: /d\" \"$f\"
echo \"$a: " & b & "\" >> \"$f\""
end try
恢复边界.scpt
try
tell application (path to frontmost application as text)
set n to name
set s to do shell script "sed -En s/^" & quoted form of n & "': (.*)/\\1/p' ~/Notes/bounds.txt"
set bounds of window 1 to words of s
end tell
end try
用于将窗口调整为特定尺寸的 AppleScript
try
tell application "Finder" to set {0, 0, dtw, dth} to bounds of window of desktop
tell application (path to frontmost application as text) to tell window 1
set b to bounds
set w to (item 3 of b) - (item 1 of b)
set h to (item 4 of b) - (item 2 of b)
set b to {dtw - w, (dth - h) / 2, dtw, dth - (dth - h) / 2}
set bounds to b
end tell
end try