سؤال

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]
هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top