简体   繁体   English

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

[英]How to resize Visual Studio Code window with Automator?

I'm trying to do a screencast and for that, I want to record the VSCode window at the same size every time.我正在尝试做一个截屏视频,为此,我想每次都以相同的大小记录 VSCode 窗口。 For that I've tried to use an Automator script to resize the window.为此,我尝试使用 Automator 脚本来调整窗口大小。 It works with all the applications that I've tested but not with VSCode.它适用于我测试过的所有应用程序,但不适用于 VSCode。

This is the script:这是脚本:

(* 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

And this is the error that happens when I try to resize the VSCode.这是我尝试调整 VSCode 大小时发生的错误。 Does anyone know what this error could be?有谁知道这个错误可能是什么? Or does anyone know any other way to enforce the window size?或者有人知道强制执行窗口大小的任何其他方法吗?

在此处输入图片说明

The bounds property and the window element only exist for applications that are scriptable . bounds属性和window元素只存在于可编写脚本的应用程序中。 Most applications, including Microsoft Visual Studio Code , are not scriptable, so your current script will not work for any of these.大多数应用程序(包括Microsoft Visual Studio Code )都不可编写脚本,因此您当前的脚本不适用于其中任何一个。

To manipulate the window of a non-scriptable application, you need to script the UI using System Events :要操作不可编写脚本的应用程序的窗口,您需要使用System Events编写 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM