【发布时间】:2011-07-06 08:51:36
【问题描述】:
在 Finder 中,使用鼠标右键菜单中的“打开方式”,我想使用命令 xterm -e vim 打开一个文本文件。
谁能告诉我怎么做?
【问题讨论】:
-
什么是“右键菜单”?您确定不想将其添加到错误的菜单中吗?
-
对不起,是'鼠标右键菜单','打开方式...'
在 Finder 中,使用鼠标右键菜单中的“打开方式”,我想使用命令 xterm -e vim 打开一个文本文件。
谁能告诉我怎么做?
【问题讨论】:
创建一个新的 Cocoa 应用程序项目。
.
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename {
[NSTask launchedTaskWithLaunchPath:@"/usr/X11/bin/xterm" arguments:[NSArray arrayWithObjects:@"-e", @"/usr/bin/vim", filename, nil]];
exit(0);
return YES;
}
通过将键 LSBackgroundOnly 添加到您的 plist 文件并将其值设置为 YES,将您的应用程序配置为仅后台应用程序:
<key>LSBackgroundOnly</key>
<true/>
通过将其添加到您的 plist 中注册为能够打开文本文件:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>Plain text document</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>text</string>
<string>txt</string>
<string>utf8</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>TEXT</string>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>text/plain</string>
</array>
<key>CFBundleTypeOSTypes</key>
<array>
<string>TEXT</string>
<string>sEXT</string>
<string>ttro</string>
</array>
</dict>
打开 MainMenu.xib,并取消选中窗口的“启动时可见”选项。
你已经完成了。建造。您可能需要使用 Finder 将其打开一次,才能让 Launch Services 知道它。
然后,在 Finder 中,您可以右键单击文本文件,然后在“打开方式...”菜单中选择您的应用,如屏幕截图所示:
【讨论】: