27
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

起動中のアプリ一覧

Posted at

現在起動中のアプリケーションの一覧を取得する。

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);
		}
	}
}
27
26
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?