(Mac)创建执行shell脚本的Xcode应用程序 [英] (Mac) Creating Xcode app that executes shell scripts

查看:1069
本文介绍了(Mac)创建执行shell脚本的Xcode应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来像我想要完成的一个简单的事情,比Xcode / Interface Builder能够做的更简单。我搜索和搜索,没有提出我的答案,但大多数搜索引导我在这里,所以我创建了一个帐户,要求专家。我想创建一个非常简单的GUI,将有四到五个按钮,每个按钮执行一个简单的shell脚本,终端窗口将不是必要的,但我可以住一个开始,如果这是它的方式。除了shell脚本,我需要在应用程序中有adb(Android调试桥)和fastboot实用程序。我假设我需要放置adb和fastboot和我的其他文件在Resources文件夹,我还假设我需要放置我的shell scrips在Classes文件夹中。我真的只需要知道如何将按钮连接到脚本,我希望它只是一个简单的东西,我忽略。提前感谢。

It seems like such a simple thing I'm trying to accomplish, much less than what Xcode / Interface Builder are capable of. I've searched and searched and not come up with my answer but most searches lead me here so I created an account to ask the experts. I want to create a very simple GUI that will have four to five buttons, each button executing a simple shell script, a terminal window won't be necessary but I can live with one starting if that's the way it is. Along with the shell scripts I need to have adb (Android debug bridge) and fastboot utility also within the app. I'm assuming I need to place adb and fastboot and my other files within the Resources folder, I'm also assuming I need to place my shell scrips within the Classes folder. I really just need to know how to connect the buttons to the scripts, I'm hoping it's just something simple that I'm overlooking. Thanks in advance.

MacBook Pro 7,1
OSX 10.6.8
Xcode 3.2.6

MacBook Pro 7,1 OSX 10.6.8 Xcode 3.2.6

推荐答案

尝试此操作

- (void)runCmd:(NSString *)cmd withArgs:(NSArray *)args
{
    if (task)
    {
        [task interrupt];

    }
    else
    {
        task = [[NSTask alloc] init];
        [task setLaunchPath:cmd];

        [task setArguments:args];

        [pipe release];

        pipe = [[NSPipe alloc] init];
        [task setStandardOutput:pipe];

        NSFileHandle* fh = [pipe fileHandleForReading];

        NSNotificationCenter* nc;

        nc = [NSNotificationCenter defaultCenter];
        [nc removeObserver:self];
        [nc addObserver:self 
               selector:@selector(dataReady:) 
                   name:NSFileHandleReadCompletionNotification 
                 object:fh];
        [nc addObserver:self selector:@selector(dataAvailable:) name:NSFileHandleDataAvailableNotification object:fh];
        [nc addObserver:self 
               selector:@selector(taskTerminated:) 
                   name:NSTaskDidTerminateNotification 
                 object:task];

        [task launch];
        [fh readInBackgroundAndNotify];
    }
}

- (void)dataAvailable:(NSNotification*)n
{
    NSLog(@"Data Available : %@",n);
}

- (void)dataReady:(NSNotification*)n
{
    NSData* d;

    d = [[n userInfo] valueForKey:NSFileHandleNotificationDataItem];

    if ([d length])
    {
        NSLog(@"Data Ready : %@",[[NSString alloc] initWithData:d encoding:NSUTF8StringEncoding]);
        [[[task standardOutput] fileHandleForReading] readInBackgroundAndNotify];
    }
}

- (void) taskTerminated:(NSNotification*)note
{
    [task release];
    task = nil;
}

这篇关于(Mac)创建执行shell脚本的Xcode应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆