2015-11-03 88 views
1

我需要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的大小,但没有将它置于屏幕中央。可能吗?

回答

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。

+0

感谢您的回复,但我这样sloved:<设置该app为“发现者” 集appHeight到412 集appWidth至678 告诉应用该app \t激活 \t重新 \t告诉应用程序“发现者”到设置的每个搜索窗口142 的侧边栏宽度端告诉 告诉应用程序“系统事件” \t告诉处理该app \t窗1的\t集大小为{appWidth,appHeight} \t end tell end tell>最后,我只需在System Preferences面板中添加Apple Script Editor.app:安全和隐私➡隐私➡辅助功能。 ︎ – user5520752

+0

这很好,如果它适合你。这在您切换应用程序时不起作用。如果应用程序可编写脚本,最好避免使用UI脚本。 – jweaks