我有以下设置:
NSWindow中的4x4(总共16个)按钮(标准NSButton按钮)网格。
当我按热键组合时,NSWindow会出现在前面(DDHotKey)
现在,我想做的是为我的按钮提供以下功能:
单击该按钮时,打开一个显示/ Applications /目录的对话框,允许我选择其中列出的任何应用程序。
当选择应用程序时,将其存储在变量(我猜)(或字符串?)中,并使其按下按键等效按钮时,该应用程序启动
我环顾四周,我不确定该做什么或真正开始寻找...任何线索?
我的appdelegate.m文件中有这个:
- (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];
}
}
}
如何将按钮链接到它?
答案 0 :(得分:2)
您可以使用NSOpenPanel
选择应用程序。
然后要启动应用程序,请查看this堆栈溢出问题。
答案 1 :(得分:1)
存储应用程序的路径,然后当您要打开它们时。您可以使用system()
功能。
system("open -a /Applications/someApplication.app");