Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

saqibjaan

macrumors member
Original poster
Feb 1, 2012
48
1
Lahore
I want to get the information about active window in Mac OSX. Can anybody help me in this regard ?

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).
 
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.
 
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.

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.
 
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.

Well, that's three different windows. Which one?

The usual question: What is it that you want to achieve?
 
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.
 
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
 
My basic requirement is that I want to know that in which window user is typing through keyboard.

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
 
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).
 
  • Like
Reactions: eternalbard
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).

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.