如何使用 Cocoa api 启动应用程序并将其置于前台? [英] How to launch application and bring it to front using Cocoa api?
本文介绍了如何使用 Cocoa api 启动应用程序并将其置于前台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对可可编程非常陌生,我找不到执行以下操作的方法:
I'm very new to a cocoa programming and I can't find the way to do the following:
- 按名称启动特定应用程序
- 做一些工作
- 稍后带来应用程序,我开始成为前端流程
从我在 Carbon API 中发现的内容来看,我应该使用的调用是 launchApplication() 和 setFrontProcess().
From what I've found in Carbon API it looks like the calls i should use are launchApplication() and setFrontProcess().
但是如何在 Cocoa 中做到这一点?IE.启动它,获取 PID,将该 PID 设置为前端进程.我试着用谷歌搜索例子,但一无所获......
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 :)
提前致谢.
推荐答案
启动应用程序:
[[NSWorkspace sharedWorkspace] launchApplication:@"/Applications/Safari.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屋!
查看全文