applescript - 无法使用 Applescript 调整窗口大小
问题描述
我使用脚本编辑器编辑了以下 Applescript,试图调整我的 RStudio 窗口的大小,但它没有用。RStudio 已加载,但未正确调整大小。代码和错误消息附在下面。有任何想法吗?我正在使用 macOS Big Sur 11.0.1 和 RStudio 1.3.1073。谢谢!
tell application "RStudio"
activate
set the bounds of the first window to {140, 0, 1160, 775}
end tell
解决方案
为了在RStudio中设置窗口的位置和大小,您需要使用系统事件以及窗口的和的值。properties
position
size
示例 AppleScript 代码:
tell application "System Events" to ¬
get properties of window 1 of application process "RStudio"
退货,例如:
{minimum value:missing value, orientation:missing value,
position:{140, 25}, class:window, accessibility description:missing value,
role description:"standard window", focused:true, title:"RStudio",
size:{1020, 750}, help:missing value, entire contents:{},
enabled:missing value, maximum value:missing value, role:"AXWindow",
value:missing value, subrole:"AXStandardWindow", selected:missing value,
name:"RStudio", description:"standard window"}
如您所见,没有bounds
property,因此将使用 and ,例如position
:size
tell application "System Events"
tell application process "RStudio"
tell window 1
set position to {140, 25}
set size to {1020, 750}
end tell
end tell
end tell
笔记:
- 属性的
list
项目,例如,不等于,而前两项确实等于,实际上需要是,因为在macOS Big Sur中, 菜单栏的默认值为 24 像素,因此与顶部的距离或屏幕到窗口的顶部。bounds
{140, 0, 1160, 775}
{position, size}
list
position
140, 0
140, 25
height
25
使用OP中属性的调整值,以下是数字表示的内容:bounds
{140, 25, 1160, 775}
- 列表项 1:{ 140 , 25, 1160, 775} - 140是从屏幕左侧到窗口左侧的距离(以像素为单位)。
- 列表项 2:{140, 25 , 1160, 775} - 25是从屏幕顶部到窗口顶部的距离(以像素为单位)。
- 列表项 3: {140, 25, 1160 , 775} - 1160是从屏幕左侧到窗口右侧的距离(以像素为单位)。
- 列表项 4:{140, 25, 1160, 775 } -- 775是从屏幕顶部到窗口底部的距离(以像素为单位)。
所以虽然 140, 25
代表的是position
,1160, 775
不是的size
。size
调整后的基础bounds
是{1020, 750}
并且是通过从 的值中减去 的值item 1
并从 的值中减去item 3
的值得出的。item 2
item 4
推荐阅读
- java - Java 套接字程序挂在读取行上
- arrays - Excel VBA自动过滤多个通配符然后更改字段值和填充
- laravel - Laravel Artisan - 如何将新列添加并填充到具有现有记录的表中?
- c# - Xamarin 重新启动应用程序后保留 SQLITE DB 的旧副本
- java - 如何在泛型类上测试 instanceof?
- python - How to crawl local HTML file with Scrapy
- hadoop - hdfs中文件的行组大小如何设置?
- r - 如何在 R 中的矩阵中删除行名和列名
- function - 关闭不返回所需的输出
- java - Java中BufferedImage的平铺,任何分辨率