我正在尝试使用 Xcode 构建一个基本的 Mac OS 应用程序,它允许用户强制弹出卡在驱动器中的 CD,而无需每次都重新启动计算机。基本上我想NSButton
在我的窗口上有一个标记为“弹出”的按钮,我正在寻找执行终端命令“drutil 托盘弹出”的按钮,以便在没有响应时从驱动器中强制弹出 CD。我是 Xcode 的新手,这是我的第一个 Mac 应用程序。
谢谢!:-)
使用NSTask
. 查看文档和Quartz Composer CommandLineTool。
+ (void) executeShellCommandAsynchronously:(NSString*)command
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSTask *task = [[[NSTask alloc] init] autorelease];
[task setLaunchPath: @"/bin/sh"]; //we are launching sh, it is wha will process command for us
[task setStandardInput:[NSFileHandle fileHandleWithNullDevice]]; //stdin is directed to /dev/null
NSArray *args = [NSArray arrayWithObjects: @"-c", //-c tells sh to execute commands from the next argument
command, //sh will read and execute the commands in this string.
nil];
[task setArguments: args];
[task launch];
[command release];
[pool release];
return;
}