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 6997501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:17:28+00:00 2026-05-27T20:17:28+00:00

Using CoreGraphics in a cocoa objective-c program running under Lion, I’d like to move

  • 0

Using CoreGraphics in a cocoa objective-c program running under Lion, I’d like to move a named window that is owned by a different process. I know I can do this via an auxiliary AppleScript method via ASOC, but I want to perform this task entirely within cocoa using CoreGraphics (or at least entirely within C or objective-c), and without any AppleScript, at all.

I know how to locate a named window of a named process using the code below, but once I get the info for that window, I haven’t been able to figure out how to move it (see the comment “What do I do here … ?” within this code). Could someone point me to some docs or make a suggestion as to how I can proceed?

Thanks in advance.

+(boolean_t)moveWindow:(NSString*)windowName ofProcess:(NSString*)processName to:(CGPoint*)location {

    boolean_t result = false;

    if (windowName == nil || processName == nil || location == nil) {
        return (result);
    }

    CFArrayRef windows = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
    CFIndex   nWindows = CFArrayGetCount(windows);

    for (CFIndex i = 0; i < nWindows; i++) {
        CFDictionaryRef windict = CFArrayGetValueAtIndex(windows, i);
        CFNumberRef winOwnerPidRef = CFDictionaryGetValue(windict, kCGWindowOwnerPID);
        if (winOwnerPidRef == nil) {
            continue;
        }
        pid_t winOwnerPid = 0;
        CFNumberGetValue(winOwnerPidRef, kCFNumberSInt32Type, (int*)&winOwnerPid);
        if (winOwnerPid < 1) {
            continue;
        }
        ProcessSerialNumber winOwnerPSN;
        GetProcessForPID(winOwnerPid, &winOwnerPSN);

        NSString* winOwner = nil;

        ProcessSerialNumber psn;
        psn.lowLongOfPSN  = kNoProcess;
        psn.highLongOfPSN = 0;

        while (winOwner == nil && GetNextProcess(&psn) == noErr) {

            if (psn.lowLongOfPSN  != winOwnerPSN.lowLongOfPSN ||
                psn.highLongOfPSN != winOwnerPSN.highLongOfPSN) {
                continue;
            }
            CFStringRef procName = NULL;
            if (CopyProcessName(&psn, &procName) == noErr) {
                winOwner = (NSString*) procName;
            }
            CFRelease(procName);
        }

        if (winOwner == nil || [winOwner compare:processName] != NSOrderedSame) {
            continue;
        }

        CFStringRef winNameRef = CFDictionaryGetValue(windict, kCGWindowName);
        NSString* winName = (NSString*) winNameRef;
        if (winName != nil && [winName compare:windowName] == NSOrderedSame) {
            // ********************************************** //
            // What do I do here in order to move the window? //
            // ********************************************** //
            result = true;
            break;
        }
    }

    return (result);
}
  • 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-27T20:17:29+00:00Added an answer on May 27, 2026 at 8:17 pm

    You can move the windows of other applications using Accessibility. Take a look at AXUIElementCreateApplication() and AXUIElementSetAttributeValue() with the attribute kAXPositionAttribute.

    Note that Accessibility will need to be enabled (check “Enable access for assistive devices” in Universal Access Preferences) or your process will need to be trusted (see AXMakeProcessTrusted())

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

Sidebar

Related Questions

I have a program that uses OpenGL combined with Cocoa and Python using PyObjC.
I have a little method that does some CoreGraphics drawing. Today I was using
I'm using this sniplet to center strings that are drawn with CoreGraphics. I can't
I am using CoreGraphics to draw a quadratic bezier but want to computer the
For my iPhone 3D apps I am currently using CoreGraphics to load png files
I understand Objective-C memory management but I'm using Core Graphics functionality such as CGRect,
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
How to draw text on imageview using coregraphics in iphone

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.