Hottest Free Downloads - DownloadPipe.com Over 197,000 downloads! Bookmark Now!
DownloadPipe.com - New Downloads Every Minute
 SEARCH:
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

applications and windows

 
   Mac (Home) -> Programmer Help RSS
Next:  How to type in ASCII?  
Author Message
jd

External


Since: Jun 24, 2005
Posts: 2



(Msg. 1) Posted: Fri Jun 24, 2005 4:09 pm
Post subject: applications and windows
Archived from groups: comp>sys>mac>programmer>help (more info?)

Hello.

I'm primarily a system programmer, unix one. Currently I have to implement
the following logic:

On Mac OS X enumerate all running application only those that are displaying
windows.
Find which of them is "active", where "active" is defined as "has focuse".
Then find name of this application and log it.

It looks like the only (well, viable, as it must be done about 10 times per
second) way to do it (for me, at last) is Carbon and Accessibility API. I
don't know much about Mac windowing system and unfortunatelly can't spend
few months learning and possibly mastering it. So I'm asking for help Smile

Here is code I got currently (highly experimental) with questions as
comments in it

<code>

#include <iostream>
#include <Carbon.h>

int main()
{
OSErr err = noErr;
OSStatus oss = noErr;
ProcessSerialNumber psn = { 0, kNoProcess };

while(1) {
// get all processes, one by one
err = GetNextProcess(&psn);

// Is there html or similar documentation for error codes?
// I know, there are headers, but I'd like something more... readable?
if(err != noErr) {
break;
}

pid_t pid;

oss = GetProcessPID(&psn, &pid);

if(oss != noErr)
continue;

CFStringRef name;

oss = CopyProcessName(&psn, &name);

if(oss != noErr)
continue;

const size_t buff_size = 256;
char buff[buff_size];

Boolean ok = CFStringGetCString(name, buff, buff_size,
kCFStringEncodingASCII);
std::cout << "name: " << buff << std::endl;

// Okay, here it begins. I'm creating an "object" representing
// application
AXUIElementRef ref = AXUIElementCreateApplication(pid);

if(!ref) {
std::cout << "ref is NULL" << std::endl;
continue;
}

AXUIElementRef top_window;

// And this one makes me go crazy. I'm currently trying
// to use uncommented parameters, but I have also tried
// others. Unfortunatelly, I can't find any usable examples
// on Apple's site - browsing through it just a week, possibly
// missing something - certainly not "search" text box Smile
err = AXUIElementCopyAttributeValue(
ref,
// kAXFocusedApplicationAttribute,
kAXFocusedWindowAttribute,
// kAXFocusedUIElementAttribute,
// kAXTopLevelUIElementAttribute,

// not quite sure if this is properly cast. Well, it is
// since this is what is required, but maybe it should be
// (const void**)(& * top_window) ?
(const void**)(&top_window)
);

if(!err) {
std::cout << "not good, yes, not good" << std::endl;
continue;
}

// is this a proper way to check this? There is no telling
// what does attribute kAXFocusedWindowAttribute returns,
// all signs on heaven and earth make me assume, that this is
// AXUIElementRef, but here:
// http://developer.apple.com/releasenotes/Accessibility/AssistiveAPI.html
// there is no such attribute and this is the only document
// with such information I could find.
if(top_window) {
std::cout << "this one has focus" << std::endl;
}

CFTypeID window_type_id = AXUIElementGetTypeID();
std::cout << "window_type_id = " << window_type_id << std::endl;

if(top_window)
CFRelease(top_window);
CFRelease(ref);
}
}

</code>

Can someone point me to any examples, clearer (and full...) documentation?
ANY help appreciated, code in pascal, geez, even assembler. I suppose in
future I'll have to write more applications using this API so I'll learn it
overtime, but now... Geeez... I'm really frustrated.

Oh, I found this:
http://www.monkeybreadsoftware.de/pluginhelp/example-Accessibilityserv...s-Activ
and it looks like it does exactly the thing I want it to do so I got logic
at least, but it doesn't help at all when it comes to write code in C,
except for attributes and functions names. And it doesn't help me that
much..

TIA,
JD
Back to top
Login to vote
Tom Harrington

External


Since: Jul 25, 2005
Posts: 193



(Msg. 2) Posted: Fri Jun 24, 2005 4:09 pm
Post subject: Re: applications and windows [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <d9h44i$pdh$1@news.supermedia.pl>,
"jd" <jedrzej.dudkiewicz RemoveThis @poczta.interia.pl> wrote:

> Can someone point me to any examples, clearer (and full...) documentation?
> ANY help appreciated, code in pascal, geez, even assembler. I suppose in
> future I'll have to write more applications using this API so I'll learn it
> overtime, but now... Geeez... I'm really frustrated.

Objective C, maybe? The easy solution to the problem you describe would
seem to be a call to [[NSWorkspace sharedWorkspace] activeApplication].

--
Tom "Tom" Harrington
Macaroni, Automated System Maintenance for Mac OS X.
Version 2.0: Delocalize, Repair Permissions, lots more.
See http://www.atomicbird.com/
Back to top
Login to vote
jd

External


Since: Jun 24, 2005
Posts: 2



(Msg. 3) Posted: Mon Jun 27, 2005 12:00 pm
Post subject: Re: applications and windows [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

> > Can someone point me to any examples, clearer (and full...)
documentation?
> > ANY help appreciated, code in pascal, geez, even assembler. I suppose in
> > future I'll have to write more applications using this API so I'll learn
it
> > overtime, but now... Geeez... I'm really frustrated.
>
> Objective C, maybe? The easy solution to the problem you describe would
> seem to be a call to [[NSWorkspace sharedWorkspace] activeApplication].

First, I don't know Objective C. Second, it will be incorporated into a
bigger program, written in C++ and I don't want to mix languages in source
files.

Does anyone knows anything about Accessibility API or knows about better,
more consistent decumentation of it? Currently I have three sources of
information: some draft regarding Accessibility API, documentation of API
and headers. When I find something interesting, like an attribute, in
headers, I can be sure, that I won't find anything about it neither in
documentation nor draft. I'm close to freaking out, I tell you Smile

JD
Back to top
Login to vote
Ben Artin

External


Since: Aug 26, 2005
Posts: 38



(Msg. 4) Posted: Mon Jun 27, 2005 12:00 pm
Post subject: Re: applications and windows [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <d9oikv$s1b$1@news.supermedia.pl>,
"jd" <jedrzej.dudkiewicz DeleteThis @poczta.interia.pl> wrote:

> Does anyone knows anything about Accessibility API or knows about better,
> more consistent decumentation of it? Currently I have three sources of
> information: some draft regarding Accessibility API, documentation of API
> and headers. When I find something interesting, like an attribute, in
> headers, I can be sure, that I won't find anything about it neither in
> documentation nor draft. I'm close to freaking out, I tell you Smile

Have you looked around <http://developer.apple.com/samplecode/index.html>? In
particular, my first step would be to use the search on Apple's site to look for
the functions you need in the sample code repository.

Ben

--
If this message helped you, consider buying an item
from my wish list: <http://artins.org/ben/wishlist>

I changed my name: <http://periodic-kingdom.org/People/NameChange.php>
Back to top
Login to vote
Display posts from previous:   
Related Topics:
NSApplication and windows within one nib - Hi, How to access to particular window defined inside the same nib file. I have one nib but I have there more than one window. It's not NSDocument, it's NSApplication and only way I found to invoke second window is : NSArray *windows =..

Advice for multiple windows design - I'm thinking of a design, where the main window uses an NSTableView. Each row in that would respond to a doubleclick action to present another window, also using NSTableView, to provide further detail from the parent's windows row. And finally..

Creating folders - a Windows Programmer Question - OK, I've been beating my head on this for a couple of days. Here's my question: In Windows if I want to create a directory path, I can recursively call a create directory function and build each part of the path using mkdir() or CreateDirectory(). ...

Safari for Microsoft Windows: How did Apple develop it? - Did they use XCode, Objective-C, Cocoa? Or GCC + GUI libs? or Visual Studio? Anyone know? I want to do the same.

Accessing Windows database file from Mac OS X? - I think I know the answer to the following question but I would like to get other opinions before answering . An amateur programmer wants to use a Mac OS X program to read data from a database stored on a Windows XP computer. There is an existing Visua...
       Mac (Home) -> Programmer Help All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum
Categories:
 Windows Forums
 Game Forums
 Linux Forums
  Mac Forums
 PDA Forums
 Mobile Forums
  Top  |  Store  |  RSS Feeds RSS  |  Data Feeds  |  Advertise  |  Submit  |  Bookmark  |  Newsletter  |  Contact