Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 453839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:12:41+00:00 2026-05-12T22:12:41+00:00

I’m trying to control windows of a foreign OSX applications from my application. I’d

  • 0

I’m trying to control windows of a foreign OSX applications from my application. I’d like
to
1. move the windows on the screen
2. resize the windows on the screen
3. change the currently active window of the application
4. get the currently active window.

(And I’d like to do this either through ObjC/C/C++ apis).

What are the API calls that I should be looking for, considering that I have the CGWindowIDs of the windows that I want to control? That is, I’d expect to find functions with signatures of something like: MoveWindow(CGWindowID winId, int x, int y), ResizeWindow(CGWindowID winId, int width, int height), Activatewindow(CGWindowID winId), CGWindowID GetCurrentlyActivatedWindow().

For 3, I’m already using SetFrontProcess to pull a process to be up front, but this doesn’t let me select the specific window of a process if it has multiple.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T22:12:41+00:00Added an answer on May 12, 2026 at 10:12 pm

    One way of doing this is indeed to use the accessibility APIs.

    An application I’m developing is doing just this to get the front window, the document path of the front window and many other attributes.

    The way I’m doing this is through AppleScript. It can be clumsy at times, but it seems to be fairly reliable. I use AppScript to send AppleScript from within my Cocoa app. It’s thread safe and more stable than the alternatives – either Scripting Bridge or NSAppleScript.

    The difficult bit will be identifying a window using it’s window ID in AppleScript – AppleScript doesn’t seem to have a window ID property that matches up to CGWindowID. However, you can get any window you want using AppleScript.

    1. Move frontmost window to 100, 100

      tell application "System Events"
       set theprocess to the first process whose frontmost is true
       set thewindow to the value of attribute "AXFocusedWindow" of theprocess
          set position of thewindow to {100, 100}
      end tell
      
    2. Resize frontmost window to 200, 300

      tell application "System Events"
        set theprocess to the first process whose frontmost is true
        set thewindow to the value of attribute "AXFocusedWindow" of theprocess
           set size of thewindow to {200, 300}
      end tell
      
    3. Change current window of the frontmost application

      tell application "System Events"
        set theprocess to the first process whose frontmost is true
        set thewindow to the value of attribute "AXFocusedWindow" of theprocess
           set size of thewindow to {200, 300}
           windows of theprocess
           -- Code to get ID of window you want to activate
           tell window 2 of theprocess -- assuming it's window 2
                 perform action "AXRaise"
           end tell
      end tell
      
    4. Window that’s active

      tell application "System Events"
       set theprocess to the first process whose frontmost is true
       set thewindow to the value of attribute "AXFocusedWindow" of theprocess
      end tell
      

    There’s an application available for AppScript called ASTranslate that will turn this AppleScript into the Objective C code that calls the relevant commands in AppScript.

    For more information on how to get the size and bounds of windows (these are read only as far as I’m aware) see the Son of Grab sample application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am currently running into a problem where an element is coming back from
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.