gpt4 book ai didi

macos - 如何使用 Automator 调整 Visual Studio Code 窗口的大小?

转载 作者:行者123 更新时间:2023-12-05 02:08:26 26 4
gpt4 key购买 nike

我正在尝试进行截屏视频,为此,我想每次都以相同的大小录制 VSCode 窗口。为此,我尝试使用 Automator 脚本来调整窗口大小。它适用于我测试过的所有应用程序,但不适用于 VSCode。

这是脚本:

(* This AppleScript will resize the current application window to the height specified below and center it in the screen. Compiled with code from Natanial Wools and Amit Agarwal *)

set the_application to (path to frontmost application as Unicode text)
set appHeight to 720
set appWidth to 1280

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 the_application
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}
end tell

这是我尝试调整 VSCode 大小时发生的错误。有谁知道这个错误可能是什么?或者有人知道任何其他强制窗口大小的方法吗?

enter image description here

最佳答案

bounds 属性和 window 元素仅存在于可编写脚本 的应用程序中。大多数应用程序(包括 Microsoft Visual Studio Code)都不可编写脚本,因此您当前的脚本不适用于其中任何一个。

要操作不可编写脚本的应用程序的窗口,您需要使用系统事件编写 UI 脚本:

tell application "System Events"
set [[screenW, screenH]] to process "Finder"'s scroll areas's size

tell (the first process where it is frontmost)
set [[null, menuH]] to the size of its menu bars
tell the front window
set [appW, appH] to its size
set its position to [¬
(screenW - appW) / 2, ¬
(screenH - appH + menuH) / 2]
end tell
end tell
end tell

关于macos - 如何使用 Automator 调整 Visual Studio Code 窗口的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60901664/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com