2011年2月14日 【 Mac Dev 】
起動中のアプリケーションを取得
特定のアプリケーションが起動中か判定したい場合は、
[[NSWorkspace sharedWorkspace] launchedApplications] から起動中のアプリケーションの情報を取得し判定する。
サンプルコード
NSEnumerator* apps = [[[NSWorkspace sharedWorkspace] launchedApplications] objectEnumerator];
NSDictionary *dict ;
while (dict = [apps nextObject]) {
NSString* bundleIdentifier = [dict objectForKey:@"NSApplicationBundleIdentifier"];
NSLog(@"bundleIdentifier : %@ ",bundleIdentifier);
}
実行結果
2011-02-14 23:08:11.391 CaptureTest[4080:a0f] bundleIdentifier : com.apple.finder 2011-02-14 23:08:11.392 CaptureTest[4080:a0f] bundleIdentifier : com.twitter.twitter-mac 2011-02-14 23:08:11.392 CaptureTest[4080:a0f] bundleIdentifier : com.apple.Xcode 2011-02-14 23:08:11.393 CaptureTest[4080:a0f] bundleIdentifier : com.apple.InterfaceBuilder3 2011-02-14 23:08:11.393 CaptureTest[4080:a0f] bundleIdentifier : com.yourcompany.CaptureTest 2011-02-14 23:08:11.393 CaptureTest[4080:a0f] bundleIdentifier : com.barebones.textwrangler 2011-02-14 23:08:11.394 CaptureTest[4080:a0f] bundleIdentifier : com.apple.iWork.Keynote 2011-02-14 23:08:11.394 CaptureTest[4080:a0f] bundleIdentifier : com.apple.iTunes 2011-02-14 23:08:11.395 CaptureTest[4080:a0f] bundleIdentifier : com.apple.Safari
例えば、iTunesが起動中か判定したい場合は、
launchedApplicationsで取得したNSDictionaryに、
キーがNSApplicationBundleIdentifier、値がcom.apple.iTunesのものがあるかで判定できる。

