2011-03-01 94 views
1

在Finder中,使用鼠標右鍵單擊菜單中的「打開方式」,我想使用命令xterm -e vim打開文本文件。如何將命令操作添加到OS X上的'打開...'

誰能告訴我該怎麼做?

+0

什麼是「正確的菜單」?你確定你不想把它添加到錯誤的菜單嗎? – 2011-03-01 09:34:13

+0

抱歉,它是'鼠標右鍵菜單','打開...' – toughtalker 2011-03-02 00:58:28

回答

3

創建一個新的Cocoa應用程序項目。

  • 將此代碼添加到您的應用程序委託.m文件:

- (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中,你可以在一個文本文件,單擊鼠標右鍵,然後在「打開方式」菜單中,選擇您的應用程序,像截圖:

enter image description here

+0

XTerm?老套。我會使用一個Terminal.app .term文件。 http://macdevcenter.com/pub/a/mac/2002/03/26/terminal_four.html?page=3 – 2011-03-02 11:49:30

+0

如果我可以點擊Upvote 100次,那麼我會這樣做。謝謝 – Mrug 2014-11-05 07:35:27

相關問題