从Applescript启动Google Chrome并设置位置

从Applescript启动Google Chrome并设置位置,applescript,Applescript,我正在制作一个启动脚本来启动各种应用程序,并设置它们的位置和大小。它适用于除chrome之外的所有产品。我需要一个脚本,检查Chrome是否打开,如果它打开当前窗口,如果它没有激活它。然后,设置其大小和位置 -- Start terminal tell application "Terminal" if (exists window 1) then reopen activate do script "screenfetch" end tell delay .5 t

我正在制作一个启动脚本来启动各种应用程序,并设置它们的位置和大小。它适用于除chrome之外的所有产品。我需要一个脚本,检查Chrome是否打开,如果它打开当前窗口,如果它没有激活它。然后,设置其大小和位置

-- Start terminal 
tell application "Terminal"
    if (exists window 1) then reopen
    activate
    do script "screenfetch"
end tell

delay .5

tell application "System Events" to tell process "Terminal"
    tell window 1
        set size to {960, 600}
        set position to {2880, 0}
    end tell
end tell

delay .5


-- Start Chrome
tell application "Google Chrome"
    if (exists window 1) then
        reopen
    else
        activate
    end if
end tell

delay .5

tell application "System Events" to tell process "Google Chrome"
    tell front window
        set size to {960, 600}
        set position to {1920, 0}
    end tell
end tell
delay .5

这对终端有效。它启动一个终端,并把它放在我的第二个显示器的右上角。然而,对于Chrome,它要么会说“找不到Chrome的窗口1”,要么会将Chrome带到前面,不会设置其大小或位置。

只要有可能,最好直接告诉应用程序做一些事情,而不是试图通过系统事件传递它。在这种情况下,Google Chrome支持AppleScript标准套件中的基本
窗口
对象,因此您可以执行以下操作:

tell application "Google Chrome"
    activate
    if ((count of windows) = 0) then
        make new window with properties {bounds:{1920, 22, 960, 622}}
    else
        set bounds of window 1 to {1920, 22, 960, 622}
    end if
end tell