如何启动应用程序,并使它可以使用Cocoa api? [英] How to launch application and bring it to front using Cocoa api?
问题描述
我是一个新的可可程序,我找不到办法做以下:
- 开始一个特殊的
- 稍后提出该应用程序我已经开始成为前台进程
/ ul>
根据我在Carbon API中发现的,我应该使用的调用是launchApplication()和setFrontProcess()。
但是如何在Cocoa中做到这一点呢?也就是说启动它,获得PID,将该PID设置为前进程。我尝试google的例子,找不到任何东西...
如果你有任何人可以提供一个简单的样品,将是真棒:)
提前感谢。
启动应用程序:
[[NSWorkspace sharedWorkspace] launchApplication:@/ Applications / Safari.app];
要激活应用程序:
NSRunningApplication * app = [NSRunningApplication
runningApplicationWithProcessIdentifier:PID];
[app activateWithOptions:NSApplicationActivateAllWindows];
//或
NSArray * apps = [NSRunningApplication
runningApplicationsWithBundleIdentifier:@com.bla.blah];
[(NSRunningApplication *)[apps objectAtIndex:0]
activateWithOptions:NSApplicationActivateAllWindows];
I'm very new to a cocoa programming and I can't find the way to do the following:
- Start a particular application by name
- Do some work
- Later bring that application I've started to be the front process
From what I've found in Carbon API it looks like the calls i should use are launchApplication() and setFrontProcess().
But how to do this in Cocoa? I.e. launch it, get PID, set that PID to be a front process. I tried to google for examples and find nothing...
If any of you can provide a minimalistic sample that would be awesome :)
Thanks in advance.
To launch an application :
[[NSWorkspace sharedWorkspace] launchApplication:@"/Applications/Safari.app"];
To activate an app :
NSRunningApplication* app = [NSRunningApplication
runningApplicationWithProcessIdentifier: PID];
[app activateWithOptions: NSApplicationActivateAllWindows];
// or
NSArray* apps = [NSRunningApplication
runningApplicationsWithBundleIdentifier:@"com.bla.blah"];
[(NSRunningApplication*)[apps objectAtIndex:0]
activateWithOptions: NSApplicationActivateAllWindows];
这篇关于如何启动应用程序,并使它可以使用Cocoa api?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!