1

What are the names of the variables (in terms of Applescript variables or otherwise) that track the currently focused application, the layout of applications in spaces, the currently focused space, and whether two applications share a space in a split view rather than 2 applications appearing in a desktop?

How does one (given a variable identifying an application) assign focus to a particular window of that application if that window resides in a split screen view?

To make the reason for asking this question concrete: the goal is to write an Applescript (or other kind of script) that assigns a keyboard shortcut that rapidly allows swapping focus between two applications that share a split screen view?

The simplest algorithm I can think of for accomplishing this (since it appears to not be a built in setting) is to

  1. get list of current spaces (including desktops, full screen applications, and split screen applications)
  2. get currently focused space
  3. if currently focused space is assigned to split-screen applications, get list of those applications and application windows (each should be length 2).
  4. get currently focused application
  5. assign focus to next element in the list of application windows in the currently focused split screen view (which should be the other application window in the currently focused split screen)

I'm not sure if this would work quite as well to solve the problem pointed out in Switch focus in split view regarding two windows of the same application, but at least this would be a start.

2

I've been searching for this answer for years, and I've become very good at tracking down hidden functionality... To no avail unfortunately. Apple has no mechanism for doing anything with spaces programmatically. The only facility I found is by running the defaults command and (under one of the defaults whose name I can't recall at the moment) there is an area that'll give you cryptic window numbers and the spaces they belong to. The issue is that list isn't updated live, so it isn't really that useful. I'm still searching, but I'm fairly certain there is no Apple-approved way to interact with spaces, or split screen, or any of its other manifestations.

EDIT: Oh yes, it's "com.apple.spaces". Run the command defaults read com.apple.spaces in the terminal to get to what I was talking about.

EDIT2: Also, there's a way to activate spaces with a little bit of C code:

CoreDockSendNotification(CFSTR("com.apple.expose.awake"));
CoreDockSendNotification(CFSTR("com.apple.expose.front.awake"));
CoreDockSendNotification(CFSTR("com.apple.showdesktop.awake"));

Each of these lines will make mission control do stuff, not that it's all that useful. There are other ways to do this...

  • defaults read com.apple.spaces works as a command line call (so I edited the answer to reflect that in case anyone else doesn't know to try that). It gives some info, and it does a good job of laying out the current split views including app information (which might be enough to write something for KM). But yea, don't know about the live info. Could you say a bit more about some of the infrastructure (header files, &c.) you would need to get to do something with that C code? Or at least a link to something apple support docs or a code example doing something similar? – mpacer Nov 25 '15 at 19:22
  • CoreDockSendNotification is undocumented, unfortunately. The C code works with the default Foundation import, although it throws a warning, probably because the function isn't exposed publicly. If you wanted to track down the missing headers (which I could do if I had the time, but...), you could remove the warning, but there's no real reason to. – William T Froggard Nov 25 '15 at 21:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .