views:

773

answers:

7

I wrote a Perl application which I run on the terminal using command lines. I created aliases for the various command options in the shell to reduce the typing. Even so, having a GUI to to select the various commands and other arguments would make it easier to run the app.

What's a good approach to developing the GUI wrapper on OSX? I bought a couple of books recommended here at Stackoverflow to learn Cocoa and Objective C. My initial thoughts to tackle this was to go with a pure Cocoa/Objective C GUI. But I also read elsewhere that Applescript can be used to interface to the command line.

What do you recommend? Go with the Cocoa/Ojbective C, Applescript, or some other approach?

I would also appreciate it if you have some recommendations to tutorials or other writeups for the approach(es) you suggest.

Thanks.

A: 

As a starter I recommend to have a look at the Moriarity sample code

epatel
A: 

I built a Cocoa GUI wrapper around rsync a while back. I used NSTask to call the command line argument. Here's some of the code, in case it helps:

- (IBAction)backup:(id)sender {
    [goButton setTitle:@"Running..."];
    [goButton setEnabled:NO];

    rsync=[[NSTask alloc] init];
    [rsync setLaunchPath:@"/usr/bin/rsync"];
    [rsync setCurrentDirectoryPath:@"/Users/user"];
    [rsync setArguments:[NSArray arrayWithObjects:@"-av",@"--delete",@"/Users/user/",@"[email protected]:/Users/user/backup/",nil]];

    NSPipe *newPipe = [[NSPipe alloc] init];
    [rsync setStandardOutput:newPipe];
    stdoutHandle = [[rsync standardOutput] fileHandleForReading];
    [newPipe release];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getData:) name:NSFileHandleReadCompletionNotification object:stdoutHandle];
    [stdoutHandle readInBackgroundAndNotify];

    [rsync launch];
}
Devin Ceartas
A: 

For no particular reason, I tend to prefer Objective-C/Cocoa.

Another solution would be Tk-Cocoa. A starting point may be found on code by Kevin blog.

mouviciel
+5  A: 

The easiest way to do it is to use Platypus.

If that doesn't suit your needs have a look at this documentation.

André Hoffmann
+2  A: 

As others above have suggested, Platypus is the easiest way. However I think that for something smaller like this, Cocoa/Objective-C isn't all that necessary. A GUI for a script could easily be made with AppleScript Studio, and the learning curve isn't as hard as ObjC/Cocoa.

Doing it in AppleScript could be as simple as this:

do shell script "/usr/bin/perl somescript.pl arg1 arg2 arg3"

Obviously you need a GUI to select the arguments, but other than that its easy.

macatomy
+1  A: 

Camelbones gives you access to Cocoa from Perl.

daotoad
A: 

Even if Cocoa isn't the easiest way to do this, it sounds like you're interested in learning it anyway. Wrapping a shell command seems as good a place as any to start.

In addition to the other tutorials recommended, I'd suggest this one on the cocoa with love blog.

http://cocoawithlove.com/2009/05/invoking-other-processes-in-cocoa.html

Ira Cooke