打开windows预设大小和位置

Open windows to preset size and position

我想知道是否有一种方法可以创建一个脚本或自动任务,以预设大小和位置打开 windows。我想用应用程序和 finder windows 来做到这一点。

例如,我想打开 Sublime 并让它占据我屏幕的上半部分,然后打开 Chrome 占据我屏幕的下半部分。
另一个例子是我想打开四个取景器windows,每个取景器占屏幕的四分之一。

我建议使用 Script Editor 编写一些 AppleScripts,以满足不同应用程序的不同布局要求。

我将使用您的第一个示例演示如何完成此操作,其中包含 SublimeGoogle Chrome],分别占据屏幕的上半部分和下半部分。

此脚本假定应用程序已经 运行 可见 window 可在每个应用程序中进行操作。它实际上是一个非常短的脚本,但看起来很长,因为我在每个阶段插入了注释行(它们以 -- 开头)以指导您完成脚本的每个部分:

    tell application "System Events"
        set Chrome to the front window of application process "Google Chrome"
        set Sublime to the front window of application process "Sublime Text"

        -- Get the size of the screen's display in pixels
        get the size of scroll area 1 of application process "Finder"
        set Display to {width:item 1, height:item 2} of the result

        -- First attempt to make Sublime take up the full width and
        -- height of the display. 
        set position of Sublime to [0, 0]
        set size of Sublime to [the Display's width, the Display's height]

        -- However, the presence of a visible menu bar and dock
        -- will create natural barriers that the window won't cross.

        -- Retrieve the actual size and position that Sublime's
        -- window ended up adopting.
        set [_w, _h] to the size of Sublime
        set [_x, _y] to the position of Sublime

        -- Half Sublime's window's height.  It should now be
        -- correctly positioned and sized.
        set the size of Sublime to [_w, _h / 2 - 1]

        -- Position Chrome first so that its horizontally aligned
        -- with Sublime, and the top edge of Chrome's window's meets 
        -- the bottom edge of Sublime's.
        set position of Chrome to [_x, _y + _h / 2]
        -- Then size Chrome's window identically to that of Sublime.
        set size of Chrome to [_w, _h / 2 - 1]
    end tell


    -- Lastly, bring both applications to the foreground
    activate application "Sublime Text"
    activate application "Google Chrome"

请记住,这只是一个简单示例,说明您如何在最佳起点下完成此任务(这两个应用程序打开时各有一个活动 window)。但是,您可能希望合并处理不太理想情况的方法,例如如果您在打开 Chrome 之前不小心触发了脚本,您希望脚本如何运行;或者,如果您希望将四个 Finder windows 排列到屏幕的不同角落,但当时打开了五个。


或者,您可以花大约 1 美元从 App Store 获得一个应用程序,它的大小和位置 windows 几乎可以按照您希望的任何方式排列。这是一个:

至少在 Sublime 我通过以下三个简单步骤解决了这个问题

  1. 把这个放在 Preferences.sublime-preferences
"remember_full_screen": true
  1. 打开sublime

  2. 手动调整 sublime window 到你想要的大小(最大高度和宽度)

☝️

在我按照这些步骤操作之后,现在每次我打开 sublime(即使使用 subl),sublime 在我 MANUALLY[=31= 的最后一个 window 打开] 调整大小。