Frage

Using NSWorkSpace launchApplication and all is fine if using an application file, but what if one would like to launch an application using a target file like untitled.rtf

[[NSWorkspace sharedWorkspace] launchApplication:selection]
War es hilfreich?

Lösung

Use -[NSWorkspace openFile:WithApplication:] like so:

[[NSWorkspace sharedWorkspace] openFile:@"/Myfiles/untitled.rtf"
    withApplication:@"TextEdit"];

Or, if one just wants to open a file with the default application for that file, use -[NSWorkspace openFile:] like so:

[[NSWorkspace sharedWorkspace] openFile:@"/Myfiles/untitled.rtf"];

The be sure to check the documentation for NSWorkspace for details and other related methods.

Andere Tipps

This will launch the proper application with only the target file.....

NSTask *task = [[NSTask alloc] init];
[task setLaunchPath: @"/usr/bin/open"];
[task setArguments: @[@"/somewhere/untitled.rtf];
[task launch];
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top