Separating full-screen applications with AppleScript

I used this script in Automator, which switches applications between full-screen and windowed modes. I am a frequent user of split-screen applications (introduced by El Capitan), so is there a way to modify this script to enable split-screen? I know that there is no keyboard layout for splitting, so this is definitely a shot in the dark.

+8
source share
1 answer

I managed to combine something while working on AppleScript / python, which I found in this MacScripter post . This does the following:

  1. Retrieves a list of open application windows from system events and allows the user to select one or two (for full screen or split screen)
  2. Launches Flight Control
  3. Dock GUI scripts for finding links to various window buttons and spaces in Mission Control that we need access to
  4. Programmatically drag buttons to create a new full-screen or split space
  5. Clicks on a newly created space to activate it

You may be able to reduce the delay time by half a second, but Mission Control expects to interact with the person and does it lazily. It will skip GUI requests that come too fast.

(* collect names of open app windows *) tell application "System Events" set windowNames to {} set theVisibleProcesses to every process whose visible is true repeat with thisProcess in theVisibleProcesses set windowNames to windowNames & (name of every window of thisProcess whose role description is "standard window") end repeat end tell (* choose 1 name for fullscreen, two names for split screen *) set selectedItems to choose from list windowNames with title "Split It" with prompt "Choose items to add to split view." with multiple selections allowed without empty selection allowed if selectedItems is false or (count of selectedItems) > 2 then return set selectedWindow1 to item 1 of selectedItems if (count of selectedItems) = 2 then set selectedWindow2 to item 2 of selectedItems end if tell application "Mission Control" launch end tell (* The dock has a set of nested UI elements for Mission Control, with the following structure: "Mission Control" group 1 (the base container) group 1, group 2, .... (groups for each desktop) buttons for open windows on each desktop group "Spaces Bar" a single button (the '+' buttan to add a new space) a list buttons for the desktops and any already-made spaces *) tell application "System Events" tell process "Dock" group "Mission Control" group 1 tell group "Spaces Bar" list 1 set {p, s} to {position, size} of last UI element set XTarget to (item 1 of p) + (item 1 of s) + 100 set YTarget to (item 2 of p) + (item 2 of s) + 100 end tell tell group 1 set viewButton1 to button selectedWindow1 set {x, y} to get viewButton1 position my mouseDrag(x, y, XTarget, YTarget, 0.5) end tell tell group "Spaces Bar" list 1 set {p, s} to {position, size} of last UI element set XTarget to (item 1 of p) + (item 1 of s) + 10 set YTarget to (item 2 of p) + (item 2 of s) + 10 end tell try tell group 1 set viewButton2 to button selectedWindow2 set {x, y} to get viewButton2 position my mouseDrag(x, y, XTarget, YTarget, 0.5) end tell end try tell group "Spaces Bar" list 1 delay 0.5 set lastUI to last UI element click lastUI end tell end tell end tell on mouseDrag(xDown, yDown, xUp, yUp, delayTime) do shell script " /usr/bin/python <<END from Quartz.CoreGraphics import CGEventCreateMouseEvent from Quartz.CoreGraphics import CGEventCreate from Quartz.CoreGraphics import CGEventPost from Quartz.CoreGraphics import kCGEventLeftMouseDown from Quartz.CoreGraphics import kCGEventLeftMouseUp from Quartz.CoreGraphics import kCGMouseButtonLeft from Quartz.CoreGraphics import kCGHIDEventTap from Quartz.CoreGraphics import kCGEventLeftMouseDragged from Quartz.CoreGraphics import kCGEventMouseMoved import time def mouseEvent(type, posx, posy): theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft) CGEventPost(kCGHIDEventTap, theEvent) def mousemove(posx,posy): mouseEvent(kCGEventMouseMoved, posx,posy); def mousedrag(posx,posy): mouseEvent(kCGEventLeftMouseDragged, posx, posy); def mousedown(posxdown,posydown): mouseEvent(kCGEventLeftMouseDown, posxdown,posydown); def mouseup(posxup,posyup): mouseEvent(kCGEventLeftMouseUp, posxup,posyup); ourEvent = CGEventCreate(None); mousemove(" & xDown & "," & yDown & "); mousedown(" & xDown & "," & yDown & "); time.sleep(" & (delayTime as text) & "); mousedrag(" & xUp & "," & yUp & "); time.sleep(" & (delayTime as text) & "); mouseup(" & xUp & "," & yUp & "); END" end mouseDrag 
+1
source

Source: https://habr.com/ru/post/1012957/


All Articles