【问题标题】:How to resize Visual Studio Code window with Automator?如何使用 Automator 调整 Visual Studio Code 窗口的大小?
【发布时间】:2020-03-28 13:18:32
【问题描述】:

我正在尝试进行截屏,为此,我想每次都以相同大小记录 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 大小时发生的错误。有谁知道这个错误可能是什么?或者有谁知道任何其他强制窗口大小的方法?

【问题讨论】:

    标签: macos visual-studio-code automator


    【解决方案1】:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-06
      • 2012-07-02
      • 2011-02-25
      • 2023-03-24
      • 1970-01-01
      • 2021-09-20
      • 2013-06-24
      • 2014-01-01
      相关资源
      最近更新 更多