Skip navigation.
 
mlRe: Obtaining the foreground application's path
FROM : Matt Burnett
DATE : Tue Mar 25 21:00:35 2008

Thanks everyone, the NSWorkspace class will most likely work for me. I 
remember seeing it years ago but havent had a need to use it untill 
now. If it turns out to be a computationally expensive method then I 
will give the carbon way a try.

On Mar 25, 2008, at 9:11 AM, Jean-Daniel Dupas wrote:

> And I know this is not what you ask for, but if you need to track 
> application usage, I suggest you to have a look at thoses carbons 
> events.
>
>  kEventAppLaunched:
>  kEventAppTerminated:
>  kEventAppFrontSwitched:
>
> It may avoid you to check the frontmost application using a timer, 
> or some other (nasty) pulling method. I know this is a Carbon call, 
> but I don't think there is a Cocoa equivalent for the "front 
> switched" event (and it's available in the 64 bits API).
>
> You can easily use them from a Cocoa Application. Just register a 
> event handler, and then it will be called when one of those event 
> occured. (if this is from a daemon application, you will have to 
> call -[NSApp run], else it will run automatically).
>
>  EventTypeSpec eventTypes[] = {
>    { kEventClassApplication, kEventAppLaunched },
>    { kEventClassApplication, kEventAppTerminated },
>    { kEventClassApplication, kEventAppFrontSwitched },
>  };
>  InstallApplicationEventHandler(yourCallBackFunction, 
> GetEventTypeCount(eventTypes), eventTypes, self, NULL);
>
>
>
> Le 25 mars 08 à 14:50, Ivan C Myrvold a écrit :

>> This will give you an NSDictionary with a lot of information about 
>> the active application:
>>
>> [[NSWorkspace sharedWorkspace] activeApplication];
>>
>> Ivan
>>
>> Den 25. mars. 2008 kl. 08:12 skrev Matt Burnett:
>>

>>> Im sure this is not the right list, but it is the closest one i 
>>> could think of for this topic (or maybe carbon-dev).
>>>
>>> I am looking to obtain the current foreground application. The 
>>> applications path, bundle identifier, or application name would be 
>>> fine, however the path would be ideal. I want to do this to track 
>>> application usage for statistical purposes for a product somewhat 
>>> similar to Altiris's Application Metering on windows. How could i 
>>> go about doing this? Also how could i deal with scenarios where 
>>> there may be more than one foreground application such as if 
>>> Spaces or Fast User Switching is enabled?
>>> _______________________________________________
>>>
>>> Cocoa-dev mailing list (<email_removed>)
>>>
>>> Please do not post admin requests or moderator comments to the list.
>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>>
>>> Help/Unsubscribe/Update your Subscription:
>>> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>>>
>>> This email sent to <email_removed>
>>>

>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list (<email_removed>)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>>
>> This email sent to <email_removed>
>>

>
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/matt.w.<email_removed>
>
> This email sent to matt.w.<email_removed>

Related mailsAuthorDate
mlObtaining the foreground application's path Matt Burnett Mar 25, 08:12
mlRe: Obtaining the foreground application's path Ivan C Myrvold Mar 25, 14:50
mlRe: Obtaining the foreground application's path Jean-Daniel Dupas Mar 25, 15:11
mlRe: Obtaining the foreground application's path Matt Burnett Mar 25, 21:00