Control Another App's Windows

Discussion in 'Mac Programming' started by Blakeasd, Oct 30, 2011.

  1. Blakeasd macrumors 6502a

    Joined:
    Dec 29, 2009
    #1
    Hello!
    I recently thought of a great idea for window management, but it would require my app to be able to reposition and resize other app's windows. Is this possible and if so what framework could I use to do it.
    Thanks! :D
     
  2. LinusR macrumors regular

    LinusR

    Joined:
    Jan 3, 2011
    #2
    As far as I know there's no way to control other windows than the ones of your app.

    Sorry
     
  3. Kenndac macrumors 6502

    Kenndac

    Joined:
    Jun 28, 2003
    #3
    This is incorrect - there are many apps already out there that manage and reposition windows belonging to other applications. Take a look at Grid on the Mac App Store, for instance.

    One way of controlling other applications' windows is to use the Accessibility APIs.
     
  4. Partron22, Oct 30, 2011
    Last edited: Oct 30, 2011

    Partron22 macrumors 68000

    Partron22

    Joined:
    Apr 13, 2011
    Location:
    Yes
    #4
    Another way to move an App's windows is through Applescript.
    This little script will move a Firefox window over and down by 10 pixels:
    Code:
    set appname to "Firefox"
    
    tell application appname to set nam to name of front window
    tell application appname to set boundsrect to bounds of window nam
    
    set newbds to {(item 1 of boundsrect) + 10, (item 2 of boundsrect) + 10, (item 3 of boundsrect) + 10, (item 4 of boundsrect) + 10}
    tell application appname to set bounds of window nam to newbds
    You can save the script as an App, or embed the script as part of your own App. Either way, it'll let you control another App's window.
     
  5. Blakeasd thread starter macrumors 6502a

    Joined:
    Dec 29, 2009
    #5
    I looked through both the Carbon and the Cocoa accessibility APIs ,but I found nothing pertaining to moving other app's windows.
    Thanks!
     
  6. LinusR macrumors regular

    LinusR

    Joined:
    Jan 3, 2011
    #6
    That's what I meant: Although there are plenty of apps which control windows there's no official API to do this.
    Some months ago I looked for even this API as well. But do you know one? I don't do.

    And the Accessibility APIs are really limited in their functionality. There aren't a lot of ways to do this you want.

    Nevertheless, never stop searching. I hope you'll find what you're looking for.

    Linus
     
  7. Partron22 macrumors 68000

    Partron22

    Joined:
    Apr 13, 2011
    Location:
    Yes
    #7
    Incidentally, that bit of AppleScript doesn't need "access for assistive devices" enabled in order to work.
    It'll move Pages documents too, and likely the windows of the majority of Mac Applications.
    The capability's been part of the OS since the mid nineties. Lion hasn't changed it much, except that you can now use XCode and Obj c to make a wrapper application for your scripts. You can do the same with Python and Ruby Scripts.
     

Share This Page