views:

48

answers:

1

I have the following (minor) problem that I want to solve programmatically. Whenever I unplug my secondary monitor from my laptop, every windows get moved to be visible in the now smaller resolution. When I plug my external monitor back in, I need to manually replace the windows to their correct position. I have to do that every morning (sigh).

Now I decided to write a simple command-line program that could save the position of every open windows and reposition them when I want to restore their positions.

I have managed to do something that works just fine by using the Accessibility API, which allows me to control windows that aren't part of my process space. I have a problem though: the program can only see the windows that are in my current space (I'm talking about the OSX Spaces feature here).

In other words, when I run my program to save the windows positions, it will only be able to save the positions of the windows in the space I'm currently in.

Some more details about my program:

  • It loops through all the processes running and get their PIDs.
  • It creates application elements from these PIDs (AXUIElementCreateApplication)
  • It gets the windows associated with this application, and then their positions

When getting the windows elements from the application element, the AXUIElementCopyAttributeValues only returns me the windows of the current space.

Now, is there a way to control any windows (across different spaces)? If not, I wouldn't mind programmatically changing spaces to get every windows, but that doesn't seem possible.

Any help would be appreciated!

+1  A: 

I'm not aware of a documented way to switch spaces.

You probably want CGSPrivate.h - CGSSetWorkspace et al. Just keep in mind those functions are SPI and can break without warning even in a 10.6.x release.

Nicholas Riley