Active Window in Mac OSX

Discussion in 'Mac Programming' started by saqibjaan, Sep 11, 2012.

  1. saqibjaan macrumors member

    Joined:
    Feb 1, 2012
    Location:
    Lahore
    #1
  2. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    What does "active window" mean? You'd better explain exactly what you mean. There are many windows, there are many that are "active" in some way. (By the way, this does not only help people giving a meaningful answer, it also helps _you_ understanding what you actually want).
     
  3. saqibjaan thread starter macrumors member

    Joined:
    Feb 1, 2012
    Location:
    Lahore
    #3
    From active window I mean the window which is in front.
    OR the window in which user is working
    OR the window which is currently selected.

    I hope everyone understands now.
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    Those can be different windows at the same time.

    Read the Window Programming Guide and carefully note the terms key and main as applied to windows.

    Then look at the class documentation for NSWindow, the methods isKeyWindow and isMainWindow. Work out how to apply them to the windows in the window-list.
     
  5. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #5
    Well, that's three different windows. Which one?

    The usual question: What is it that you want to achieve?
     
  6. KnightWRX macrumors Pentium

    KnightWRX

    Joined:
    Jan 28, 2009
    Location:
    Quebec, Canada
    #6
    I think the guy wants to find out the Window that is currently focused in the Window manager, not just in his app. Was pretty clear from his first post.

    From searching, I don't think it's quite possible. You could get the current active application from an NSWorkspace instance ([NSWorkspace sharedWorkspace]) and get an array of running applications using the runningApplications method. You can then check the active property of each NSRunningApplication instance in the array.

    But an NSRunningApplication instance cannot give you the application's window list.
     
  7. saqibjaan thread starter macrumors member

    Joined:
    Feb 1, 2012
    Location:
    Lahore
    #7
    Thanks chown33. IsKeyWindow and IsMainWindow doesn't help my cause.

    My basic requirement is that I want to know that in which window user is typing through keyboard.

    Regards
    Saqib
     
  8. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #8
    You need to be more specific.

    Is this something that you need to determine from another app? In your own app?

    If isKeyWindow and isMainWindow don't help, you need to explain why not. Is it because they only apply to windows in the current process, and you need to find the key window in another process? Some other reason?

    You should read this, and apply what it says:
    http://www.mikeash.com/getting_answers.html
     
  9. saqibjaan thread starter macrumors member

    Joined:
    Feb 1, 2012
    Location:
    Lahore
    #9
    I get the name of the current keyWindow (focused window) through this code.

    NSDictionary *activeApp = [[NSWorkspace sharedWorkspace] activeApplication];

    NSLog(@"Active application is: %@", (NSString *)[activeApp objectForKey:mad:"NSApplicationName"]);

    Can anyone help me in getting current window title?

    I am not talking about app current window title but any program which is currently focused (selected).
     
  10. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #10
    That is most likely considered none of your business. That is what "sandboxing" is all about, that your app shouldn't be able to interfere with other apps. You can use AppleScript to ask the application, if it is willing to volunteer that information.
     
  11. saqibjaan thread starter macrumors member

    Joined:
    Feb 1, 2012
    Location:
    Lahore
    #11
    gnasher729, you don't have to tell me that what's my business and what's not.
     
  12. KnightWRX macrumors Pentium

    KnightWRX

    Joined:
    Jan 28, 2009
    Location:
    Quebec, Canada
    #12

Share This Page