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

Die*_*des 3 macos automator visual-studio-code

我正在尝试进行截屏视频,为此,我想每次都以相同的大小记录 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
Run Code Online (Sandbox Code Playgroud)

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

在此输入图像描述

CJK*_*CJK 5

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

\n

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

\n
tell application "System Events"\n    set [[screenW, screenH]] to process "Finder"\'s scroll areas\'s size\n    \n    tell (the first process where it is frontmost)\n        set [[null, menuH]] to the size of its menu bars\n        tell the front window\n            set [appW, appH] to its size\n            set its position to [\xc2\xac\n                (screenW - appW) / 2, \xc2\xac\n                (screenH - appH + menuH) / 2]\n        end tell\n    end tell\nend tell\n
Run Code Online (Sandbox Code Playgroud)\n