xcode 如何在 OSX 中为命令行工具制作 GUI 前端?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2592479/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:15:57  来源:igfitidea点击:

How can I make a GUI frontend to a command line tool in OSX?

cocoaxcodeuser-interfacecommand-linefrontend

提问by fregante

I'm dying to know how I can make a GUI for ffmpegand jheadin OSX. I've been looking for a solution for a while and thought you, stackoverflow's users, could help me. Maybe you know some document I haven't come across of or, better, a tutorial to make a GUI.

我很想知道如何在 OSX 中为ffmpegjhead制作 GUI 。我一直在寻找解决方案一段时间,并认为您,stackoverflow 的用户,可以帮助我。也许您知道一些我没有遇到过的文档,或者更好的是制作 GUI 的教程。

I love those two tools but I like the simplicity of drag/drop operations.

我喜欢这两个工具,但我喜欢拖放操作的简单性。

Note: I don't need a GUI for them, I want to make one.

注意:我不需要它们的 GUI,我想制作一个。

采纳答案by Kelan

There is a tutorial for wrapping command-line tools using NSTask, on the Cocoa Dev Central site:

在 Cocoa Dev Central 站点上有一个使用 NSTask 包装命令行工具的教程:

It's a few years old now, but should get you started.

现在已经有几年了,但应该让你开始。

回答by JeremyP

If you are asking "How do I create a GUI application in Mac OS X that interfaces to a command line tool" the answer is NSTask. Although, if the command line tool provides a programming API, using that would be preferable to invoking the command line tool itself.

如果您问“如何在 Mac OS X 中创建与命令行工具接口的 GUI 应用程序”,那么答案是NSTask。但是,如果命令行工具提供了编程 API,那么使用它比调用命令行工具本身更可取。

If you are asking "How do I create a GUI application in Mac OS X" the answer is to read a book about it and look at the Apple tutorial docs. Cocoa Programming on Mac OS Xby Aaron Hillegass was my starting point.

如果您问“如何在 Mac OS X 中创建 GUI 应用程序”,答案是阅读有关它的书并查看 Apple 教程文档。 Aaron Hillegass在 Mac OS X 上的 Cocoa Programming是我的起点。

回答by user1449303

First create a Modal Dialog NIB with the needed GUI.
When called in C , create an NSReleasePool, and then the magic sauce.

首先使用所需的 GUI 创建一个 Modal Dialog NIB。
在 C 中调用时,创建一个 NSReleasePool,然后创建魔法酱。

[NSApplication sharedApplication]     
ProcessSerialNumber psn;
GetCurrentProcess( &psn );
TransformProcessType(&psn,kProcessTransformToForegroundApplication);
SetFrontProcess( &psn );

Later after you load the NIB from the Bundle, issue

稍后从 Bundle 加载 NIB 后,发出

[NSApp runModalForWindow:[controller window]];
[[controller window] close];

Without the TransfromProcessType(), the Terminal app will get keystrokes, not the Modal Dialog.

如果没有 TransfromProcessType(),终端应用程序将获得按键,而不是模态对话框。

回答by Bryan Oakley

You can use a scripting language like Tcl, Python or Ruby with a toolkit like Tk which uses native widgets on the mac.

您可以将 Tcl、Python 或 Ruby 等脚本语言与 Tk 等工具包一起使用,该工具包在 mac 上使用本机小部件。

回答by TalkingCode

This may not be the best answer but in the book "Xcode unleashed" is a chapter how to embed a Command Line Tool inside a Cocoa Application. Maybe you should have a look. Nice book anyway.

这可能不是最好的答案,但在“Xcode unleashed”一书中,有一章如何在 Cocoa 应用程序中嵌入命令行工具。也许你应该看看。总之是好书。

回答by Michael Aaron Safyan

You are too late, there is already a GUI frontend for ffmpeg called ffmpegX, but anyway, you would create a model that either wraps or uses the library or executable.... if it uses the executable you can use popento invoke the executable, write to its STDIN, and read from its STDOUT. The view and controller would be basically the same as you would design it for any other GUI application. Since this is a Cocoa post, you could use Objective-C and Cocoa to the make the GUI, but it really can be implemented in any language.

你太晚了,已经有一个名为ffmpegX 的ffmpeg 的 GUI 前端,但无论如何,你会创建一个模型来包装或使用库或可执行文件......如果它使用可执行文件,你可以使用popen来调用可执行文件,写入其 STDIN,并从其 STDOUT 读取。视图和控制器与您为任何其他 GUI 应用程序设计的基本相同。由于这是 Cocoa 帖子,您可以使用 Objective-C 和 Cocoa 来制作 GUI,但它确实可以用任何语言实现。

回答by Shyam

On your Leopard/Snow Leopard disk you can find XCode, but you can also download it from the Apple Developer Community. XCode comes with the Interface Builder, which lets you build GUI's and you can rig to your commands using the Cocoa framework.

在 Leopard/Snow Leopard 磁盘上,您可以找到 XCode,但您也可以从 Apple Developer Community 下载它。XCode 带有 Interface Builder,它允许您构建 GUI,并且您可以使用 Cocoa 框架绑定到您的命令。