How do I launch the appropriate application for a file?
Submitted by on Wednesday, 6 December, 2006 - 19:34
I am trying to write a macro that opens the file named in the selection with the appropriate application. For example, [mysheet.xls] would start Excel and open the file mysheet.xls, [mytext.txt] would open Notepad...
I've tried sending the filename to cmd.exe, but that doesn't work. I've tried sending it to Explorer but that just views it in explorer.
Here's what I have (not working properly):
// launch app to open file NOT WORKING!
/*
os = System.getProperty("os.name");
if(os.indexOf("Windows 9") == -1 && os.indexOf("Windows M") == -1) {
comspec = "cmd.exe /C ";
} else {
comspec = "command.exe /C ";
}
*/
comspec="explorer.exe ";
if (myfile.matches("[\\/]")) {
command=comspec+myfile;
} else {
// handle relative paths:
command=comspec+buffer.getDirectory()+myfile;
}
// Macros.error( view, "launching "+command);
setAccessibility(true);
runtime = new java.lang.Runtime();
runtime.exec(command);
return;

