Zrb0529
Zrb0529

Reputation: 800

Cocoa Button Launch outside Application

I have the following setup:

A grid of 4x4 (16 total) buttons (standard NSButton buttons) in an NSWindow.

The NSWindow will come to the front when I press a hotkey combination (DDHotKey)

Now, what I'd like to do is give my buttons the following functionality:

I'm looking around and I'm not exactly sure what to do or really where to begin looking...any clues?

I have this in my appdelegate.m file:

- (void)openDoc:(id)sender
{
    int result;
    NSArray *fileTypes = [NSArray arrayWithObject:@"td"];
    NSOpenPanel *oPanel = [NSOpenPanel openPanel];

[oPanel setAllowsMultipleSelection:YES];
result = [oPanel runModalForDirectory:NSHomeDirectory()
                file:nil types:fileTypes];
if (result == NSOKButton) {
    NSArray *filesToOpen = [oPanel filenames];
    int i, count = [filesToOpen count];
    for (i=0; i<count; i++) {
        NSString *aFile = [filesToOpen objectAtIndex:i];
        id currentDoc = [[ToDoDoc alloc] initWithFile:aFile];
    }
}
}

How do I link the button to it?

Upvotes: 0

Views: 255

Answers (2)

Grady Player
Grady Player

Reputation: 14549

store the path to application, then when you want to open them. You can use the system() function.

system("open -a /Applications/someApplication.app");

Upvotes: 1

edc1591
edc1591

Reputation: 10182

You can use an NSOpenPanel to choose the application.

Then to launch the application, take a look at this stack overflow question.

Upvotes: 2

Related Questions