Ricardo Brugos
Ricardo Brugos

Reputation: 1

Applescript to open two applications in the same full screen mode (side by side)?

I would like to open in full screen mode two applications side by side. For example, Calendar and reminders in full screen together.

One example I have seen and use is this:

tell application "Safari" to activate tell application "System Events" keystroke "f" using {command down, control down} end tell

But this only to opens one application in full, how do I add the other application or window in in the right or left of the seme full screen?

thanks.

Upvotes: 0

Views: 232

Answers (1)

Robert Kniazidis
Robert Kniazidis

Reputation: 1878

It is not possible to split the screen into 2 windows of 2 applications in full screen mode.

It is possible to split the screen into 2 windows of 2 applications in maximized mode, but here you need to take into account 2 aspects:

  1. you need to take into account that some part of the screen is occupied by the menubar and the dock,

  2. applications have a window reduction limit. For example, if you try to reduce the width of the Calendar.app window below the allowed limit, the application ignores the reduction and sets the minimum width allowed.

The following is an example of screen division. First, the available screen limits are found minus the menubar and dock. The script then tries to shrink the Calendar window to the middle of the allowed area. Normally, Calendar will automatically set the width limit.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

-- find usable screen Bounds using Applescript Objective-C (AsObjC)
set wholeFrame to current application's NSScreen's mainScreen()'s frame()
set visibleFrame to current application's NSScreen's mainScreen()'s visibleFrame()
set x1 to (current application's NSMinX(visibleFrame)) as integer
set y1 to ((current application's NSMaxY(wholeFrame)) - (current application's NSMaxY(visibleFrame))) as integer
set x2 to (current application's NSMaxX(visibleFrame)) as integer
set y2 to (y1 + (current application's NSHeight(visibleFrame))) as integer
set usableBounds to {x1, y1, x2, y2}

set middleX to (x2 - x1) / 2 as integer -- first, we try to split here

tell application "Calendar"
    activate
    set bounds of front window to {x1, y1, middleX, y2}
    -- Calendar.app will limit width reduction, so we have to find middleX again
    set {x1, y1, middleX, y2} to bounds of front window
end tell

tell application "Reminders"
    activate
    set bounds of front window to {middleX + 1, y1, x2, y2}
end tell

Upvotes: 1

Related Questions