How to permanently put TextEdit in the Open with... menu list?

I'm a developer and often dealing with unusual file types. If I want to open one of these files in TextEdit, I have to start it first and then open the file with it, or drag the file to the TextEdit icon.

Is there a way to permanently put the TextEdit.app into the Open with... menu list no matter what file type I'm looking at?

Of course this procedure will be useful for whatever text editor you choose if TextEdit isn't your cup of tea.


The only way to do this with all file types is to create a service in automator, which actually should make things easier for you.

  1. Open Automator and select "Service".
  2. In the "Service receives selected..." dropdown, change it to read "receives selected files and folders in any application"
  3. Select Utilities from the library menu in the left pane and double-click "Run Shell Script"
  4. Change the "Pass Input" dropdown to "as arguments"
  5. Delete the default script and replace with the following:

    if [ -f "$1" ] ; then
        open -a "TextEdit" "$1" ;
    fi
    

Save this file as whatever you want it to show up as in your contextual menu, something like "Open With TextEdit" and you're done, you'll now have the option to open any file with text edit.

It won't be in the open with menu, it will be a separate item in the contextual menu grouped with any other services you have running.

On a side note, if you're developing on a mac you should really think about using a better text editor like TextMate or TextWrangler or Sublime Text, some of these even add the service for you to save you doing all of the above.


You can add supported file types by editing the Info.plist, but I don't know any way to do that for all file types. Adding UTIs like public.data or public.item to an Info.plist or com.apple.LaunchServices.plist doesn't seem to work.

I have used duti to make TextMate the default application for different plain text types:

# plain text files without an extension
com.macromates.TextMate.preview public.plain-text all

# executable scripts
com.macromates.TextMate.preview public.unix-executable all

com.macromates.TextMate.preview .as all
com.macromates.TextMate.preview .ass all
com.macromates.TextMate.preview .bash all
com.macromates.TextMate.preview .bom all
com.macromates.TextMate.preview .c all
com.macromates.TextMate.preview .cfm all
com.macromates.TextMate.preview .cfml all
com.macromates.TextMate.preview .class all
com.macromates.TextMate.preview .coffee all
com.macromates.TextMate.preview .conf all
com.macromates.TextMate.preview .cpp all
com.macromates.TextMate.preview .css all
com.macromates.TextMate.preview .csv all
com.macromates.TextMate.preview .ctp all
com.macromates.TextMate.preview .dat all
com.macromates.TextMate.preview .data all
com.macromates.TextMate.preview .doc all
com.macromates.TextMate.preview .erb all
com.macromates.TextMate.preview .fields all
com.macromates.TextMate.preview .gemspec all
com.macromates.TextMate.preview .h all
com.macromates.TextMate.preview .haml all
com.macromates.TextMate.preview .hotkey all
com.macromates.TextMate.preview .hpp all
com.macromates.TextMate.preview .idx all
com.macromates.TextMate.preview .java all
com.macromates.TextMate.preview .js all
com.macromates.TextMate.preview .json all
com.macromates.TextMate.preview .keylayout all
com.macromates.TextMate.preview .kmlibrary all
com.macromates.TextMate.preview .less all
com.macromates.TextMate.preview .log all
com.macromates.TextMate.preview .m all
com.macromates.TextMate.preview .manifest all
com.macromates.TextMate.preview .md all
com.macromates.TextMate.preview .mm all
com.macromates.TextMate.preview .msass all
com.macromates.TextMate.preview .opml all
com.macromates.TextMate.preview .pg all
com.macromates.TextMate.preview .php all
com.macromates.TextMate.preview .pl all
com.macromates.TextMate.preview .plist all
com.macromates.TextMate.preview .plist all
com.macromates.TextMate.preview .py all
com.macromates.TextMate.preview .rb all
com.macromates.TextMate.preview .rd all
com.macromates.TextMate.preview .rdoc all
com.macromates.TextMate.preview .readme all
com.macromates.TextMate.preview .rhtml all
com.macromates.TextMate.preview .rst all
com.macromates.TextMate.preview .sb all
com.macromates.TextMate.preview .scss all
com.macromates.TextMate.preview .sh all
com.macromates.TextMate.preview .srt all
com.macromates.TextMate.preview .strings all
com.macromates.TextMate.preview .sub all
com.macromates.TextMate.preview .tex all
com.macromates.TextMate.preview .tsv all
com.macromates.TextMate.preview .utf all
com.macromates.TextMate.preview .xml all
com.macromates.TextMate.preview .yaml all

duti doesn't support just adding applications to open with menus without making them default though.


Here's an adaptation of @JamiePatt's accepted answer, using user48595's improvement, with the addition that it will make TextEdit the default application to open the file before actually opening it. This means that in the future the file can be opened the ordinary way.

  1. Verify the hexidecimal code by running xattr -p com.apple.LaunchServices.OpenWith <file>, where 'file' is some file you've manually set to open with TextEdit.

  2. Open Automator and choose type "Service" for your document.

  3. Under dropdown "Service receives selected", select "files or folders".

  4. Add step "Utilities -> Set Value of Variable". You should see a variable named "Storage".

  5. Add step "Utilities -> Run Shell Script". Under dropdown "pass input", select "as arguments". Replace the contents of the text field with the below, making sure the hexadecimal code is the same as what you got from the first step.

    if [ -f "$1" ] ; then
        xattr -wx com.apple.LaunchServices.OpenWith "62 70 6C 69 73 74 30 30 D3 01 02 03 04 05 06 57 76 65 72 73 69 6F 6E 54 70 61 74 68 5F 10 10 62 75 6E 64 6C 65 69 64 65 6E 74 69 66 69 65 72 10 00 5F 10 1A 2F 41 70 70 6C 69 63 61 74 69 6F 6E 73 2F 54 65 78 74 45 64 69 74 2E 61 70 70 5F 10 12 63 6F 6D 2E 61 70 70 6C 65 2E 54 65 78 74 45 64 69 74 08 0F 17 1C 2F 31 4E 00 00 00 00 00 00 01 01 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 63" "$1";
        xattr -d com.apple.quarantine "$1" || true;
    fi
    
  6. Add step "Utilities -> Get Value of Variable". You should see a variable named "Storage".

  7. Add step "Files & Folders -> Open Finder Items". Under "Open with" dropdown, select "TextEdit".

  8. Save with a memorable name, such as TextEditify.

The first time you want to open a non-TextEdit document, you'll have to select TextEditify from the right-click menu. Subsequent opens can happen the normal way.

Explanation of script:

The first xattr command adds the attribute usually saved if you select "always open with" manually.

The second xattr command makes sure that this works with files downloaded from the Internet.