Как изменить размер окна кода Visual Studio с помощью Automator? - PullRequest
0 голосов
/ 28 марта 2020

Я пытаюсь сделать скринкаст, и для этого я хочу каждый раз записывать окно 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

1 Ответ

0 голосов
/ 30 марта 2020

Свойство bounds и элемент window существуют только для приложений, которые scriptable . Большинство приложений, включая код Microsoft Visual Studio , не являются сценариями, поэтому ваш текущий сценарий не будет работать ни для одного из них.

Для управления окном приложения, не поддерживающего сценарии, вам необходимо для сценария пользовательского интерфейса, используя Системные события :

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
...