30

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.

1
  • 1
    I have this desire, also. Currently, I keep TextEdit in my Dock, so it is always available to drag a file onto.
    – GEdgar
    May 2, 2013 at 18:30

6 Answers 6

20

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.

4
  • 1
    +1, and yeah, TextEdit isn't a real plaintext editor--it can do it, but it doesn't have any features to make it easier, and would much rather be editing rich text.
    – NReilingh
    Aug 13, 2012 at 22:18
  • Beautiful! It would be even better if we could restrict this to all files in a text format (including source code and the like) Mar 8, 2014 at 16:39
  • 1
    is there any way to make it appear in the main menu instead of having to search for in the service menu? Or at least to hide unused items in service menu...
    – pqnet
    Aug 12, 2014 at 8:24
  • @pqnet - did you find how to do this? I'm looking for this too: apple.stackexchange.com/questions/206068/…
    – Chris Snow
    Sep 17, 2015 at 11:55
7

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.

2

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.

2
  1. Open the Automator application

  2. Click New Document

  3. Choose Service

    enter image description here

  4. Change the Services receives selected to "files or folders"

    enter image description here

  5. Search for the Action "Open Finder Items" and drag it into the workflow space

    gif

  6. Change Open with: to "TextEdit" or whatever application you wish (I prefer "Visual Studio Code")

  7. Save your service something logical, like "Open with TextEdit" if you chose TextEdit.

You can now right-click any Finder item and choose Services->Open with TextEdit!

Thanks to user48595 and the link posted in his answer: http://www.mactricksandtips.com/2013/05/add-open-with-textedit-or-any-other-app-to-right-click-menu-item.html

1

You can create a Service menu workflow as influencejamie describes. However you can just use the 'Open Finder Items' option and add TextEdit as the app.

There is a good post about it here, which explains how to create the workflow in more detail.

1
  • 2
    Answers on Ask Different need to be more than just a link. It's okay to include a link, but please summarize or excerpt it in the answer. The idea is to make the answer stand alone.
    – nohillside
    May 2, 2013 at 19:04
-3

Just use the option "-e" to open with TextEdit: open -e yourfile.whatever and it'll open it in TextEdit.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .