更改窗口的边界

时间:2015-11-03 15:33:01

标签: macos applescript

我需要Apple脚本的帮助。我不是这方面的专家。脚本是这样的:

(*

This Apple script will resize any program window to an exact size and the window is then moved to the center of your screen.
Specify the program name, height and width below and run the script.

Written by Amit Agarwal on December 10, 2013

*)

set theApp to "Finder"
set appHeight to 412
set appWidth to 678

tell application "Finder"
    set screenResolution to bounds of window of desktop
end tell

set screenWidth to item 3 of screenResolution
set screenHeight to item 4 of screenResolution

tell application theApp
    activate
    reopen
    set yAxis to (screenHeight - appHeight) / 2 as integer
    set xAxis to (screenWidth - appWidth) / 2 as integer
    set the bounds of the first window to {xAxis, yAxis, appWidth + xAxis, appHeight + yAxis}
    tell application "Finder" to set the sidebar width of every Finder window to 142
end tell

我想调整Finder的大小,但没有将其置于屏幕中心。有可能吗?

1 个答案:

答案 0 :(得分:0)

逻辑是,你得到前窗的当前界限。边界中的前两项是x轴上的起始水平点和y轴上的起始垂直点。 (换句话说,前两项是左上角的坐标) 一旦你有了这些,你设置新的边界,保持边界描述中的前两个项目相同,然后将所需的宽度和高度添加到后两个点以调整窗口大小。

set theApp to "Finder"
set appHeight to 412
set appWidth to 678

tell application theApp
    activate
    set {startHoriz, startVert, endHoriz, endVert} to bounds of the first window
    set the bounds of the first window to {startHoriz, startVert, startHoriz + appWidth, startVert + appHeight}
end tell
tell application "Finder" to set the sidebar width of every Finder window to 142

如果要将窗口一直向左移动,可以在设置窗口边界之前将startHoriz更改为1.