現在起動中のアプリケーションの一覧を取得する。
Objective-C
// 自分自身のプロセス
ProcessSerialNumber ourPSN;
GetCurrentProcess(&ourPSN);
// 起動中のプロセスを一覧
ProcessSerialNumber nextPSN = {kNoProcess, kNoProcess}; // 初期化
while (GetNextProcess(&nextPSN) == noErr)
{
Boolean processIsUs = false;
SameProcess(&ourPSN, &nextPSN, &processIsUs);
if (processIsUs)
{
// 自分自身のプロセス
}
else
{
CFDictionaryRef info;
info = ProcessInformationCopyDictionary(&nextPSN, kProcessDictionaryIncludeAllInformationMask);
if (info)
{
NSLog(@"PSN:%@", CFDictionaryGetValue(info, CFSTR("PSN")));
NSLog(@"Flavor:%@", CFDictionaryGetValue(info, CFSTR("Flavor")));
NSLog(@"Attributes:%@", CFDictionaryGetValue(info, CFSTR("Attributes")));
NSLog(@"ParentPSN:%@", CFDictionaryGetValue(info, CFSTR("ParentPSN")));
NSLog(@"FileType:%@", CFDictionaryGetValue(info, CFSTR("FileType")));
NSLog(@"FileCreator:%@", CFDictionaryGetValue(info, CFSTR("FileCreator")));
NSLog(@"pid:%@", CFDictionaryGetValue(info, CFSTR("pid")));
NSLog(@"LSBackgroundOnly:%@", CFDictionaryGetValue(info, CFSTR("LSBackgroundOnly")));
NSLog(@"LSUIElement:%@", CFDictionaryGetValue(info, CFSTR("LSUIElement")));
NSLog(@"IsHiddenAttr:%@", CFDictionaryGetValue(info, CFSTR("IsHiddenAttr")));
NSLog(@"IsCheckedInAttr:%@", CFDictionaryGetValue(info, CFSTR("IsCheckedInAttr")));
NSLog(@"RequiresCarbon:%@", CFDictionaryGetValue(info, CFSTR("RequiresCarbon")));
NSLog(@"LSUserQuitOnly:%@", CFDictionaryGetValue(info, CFSTR("LSUserQuitOnly")));
NSLog(@"LSUIPresentationMode:%@", CFDictionaryGetValue(info, CFSTR("LSUIPresentationMode")));
NSLog(@"BundlePath:%@", CFDictionaryGetValue(info, CFSTR("BundlePath")));
NSLog(@"kCFBundleExecutableKey:%@", CFDictionaryGetValue(info, kCFBundleExecutableKey));
NSLog(@"kCFBundleNameKey:%@", CFDictionaryGetValue(info, kCFBundleNameKey));
NSLog(@"kCFBundleIdentifierKey:%@", CFDictionaryGetValue(info, kCFBundleIdentifierKey));
CFRelease(info);
}
// ローカライズされたプロセス名が取得できる
CFStringRef name;
if (CopyProcessName(&nextPSN, &name) == noErr)
{
NSLog(@"name:%@", name);
CFRelease(name);
}
}
}