Question

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:

  • When the button is clicked, open a dialog that shows the /Applications/ directory and allow me to select any of the applications listed there.

  • When the application is selected store it in a variable (I'm guessing) (or string?) and make it so that when the buttons Key Equivalent is pressed, that application launches

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?

Was it helpful?

Solution

You can use an NSOpenPanel to choose the application.

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

OTHER TIPS

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

system("open -a /Applications/someApplication.app");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top