Repositioning another app's windows?

  • Hi. I frequently add and remove external monitors from my laptop. Each time I do this, the windows all get rearranged.

    I wonder if it's not possible to write an agent that listens for screen geometry changes, and repositions app windows in the right place each time a monitor is added or removed.

    If this utility already exists, I'd love to hear about it. If not, is there a reliable way to get at all the windows currently instantiated, and determine which they are? I've looked briefly at the accessibility APIs, and that might do the trick. But I wonder if there's not another way I should consider.

    I know I can listen for screen geometry changes, I've done it before (gonna have to dig up that code).

    Thanks!

    --
    Rick
  • Use Accessibility. There's a utility called Moom that does that. That's the only way an outside app can move some of my windows, because the window positioning code path is convoluted - consider just what's involved in moving a window whose position comes from the OS inside a virtual machine.

    Even normal apps may get confused at a move that doesn't come in via expected channels.

    ----- Original Message -----
    From: "Rick Mann" <rmann...>
    To: "Cocoa-Dev List" <cocoa-dev...>
    Sent: Saturday, July 28, 2012 7:50:00 PM
    Subject: Repositioning another app's windows?

    Hi. I frequently add and remove external monitors from my laptop. Each time I do this, the windows all get rearranged.

    I wonder if it's not possible to write an agent that listens for screen geometry changes, and repositions app windows in the right place each time a monitor is added or removed.

    If this utility already exists, I'd love to hear about it. If not, is there a reliable way to get at all the windows currently instantiated, and determine which they are? I've looked briefly at the accessibility APIs, and that might do the trick. But I wonder if there's not another way I should consider.

    I know I can listen for screen geometry changes, I've done it before (gonna have to dig up that code).

    Thanks!

    --
    Rick
  • On 2012 Jul 28, at 21:48, Lee Ann Rucker <lrucker...> wrote:

    > Use Accessibility. There's a utility called Moom that does that.

    or AppleScript; moving windows is in the Standard Suite, so I think any app which announces itself as scriptable can have its windows moved.

    Neither way is 100% reliable.  Accessibility probably requires that "Enable Access for assistive devices" be on in System Preferences.  I don't see why we have that stupid checkbox.  At least, in 10.8 it's on by default in a new account.
  • On Jul 31, 2012, at 11:18 PM, Jerry Krinock <jerry...> wrote:

    > Neither way is 100% reliable.  Accessibility probably requires that "Enable Access for assistive devices" be on in System Preferences.  I don't see why we have that stupid checkbox.  At least, in 10.8 it's on by default in a new account.

    My guess is that Apple probably considered it a security flaw to have applications able to control applications' GUI elements by default.

    Charles
  • On Aug 1, 2012, at 11:38 , <cocoa-dev-request...> wrote:
    > Date: Wed, 01 Aug 2012 01:07:15 -0500
    > From: Charles Srstka <cocoadev...>
    > Message-ID: <DE24B739-4444-4A0D-B97C-B3C4BF4C292E...>
    >
    > On Jul 31, 2012, at 11:18 PM, Jerry Krinock <jerry...> wrote:
    >
    >> Neither way is 100% reliable.  Accessibility probably requires that "Enable Access for assistive devices" be on in System Preferences.  I don't see why we have that stupid checkbox.  At least, in 10.8 it's on by default in a new account.
    >
    > My guess is that Apple probably considered it a security flaw to have applications able to control applications' GUI elements by default.

    Using the checkbox gives blanket permission for all processes, which is rather extreme.

    A workaround for the "Enable Access" checkbox is to call AXMakeProcessTrusted() on your binary, which sets the setgid bit and uses a special "accessibility" group - needing a complex dance nowadays to ask for the admin password. (And, of course, making the app uneligible for the Mac App Store.) A similar reasoning applies to using event taps.

    I have an open enhancement request (rdar:///9507141) to use entitlements for this, proposing, for instance:
    > - com.apple.security.events.keyboard - allows the process to install keyboard event taps
    > - com.apple.security.events.mouse - allows the process to install mouse event taps
    > - com.apple.security.events.other - allows the process to install other/special taps
    > - com.apple.security.accessibility - allows the process to use accessibility even if turned off in System Preferences.
    > - This also opens up the possibility of the system alerting the user the first time an application with these capabilities is run, or even downloaded.

    Feel free to dupe or expand on this.
    --
    Rainer Brockerhoff  <rainer...>
    Belo Horizonte, Brazil
    "In the affairs of others even fools are wise
    In their own business even sages err."
    Weblog: http://www.brockerhoff.net/blog
previous month july 2012 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today