294

In windows I right click and then there is an option to create a text file.

How to do so in mac?

Ricardo
  • 406
user4951
  • 3,491
  • 4
  • 22
  • 24

30 Answers30

102

You can also do this in Terminal. Go to the directory where you want to create the file, then run the following:

touch file.txt

Or redirect 'nothing' to a text file

> file.txt
CousinCocaine
  • 10,098
  • 19
    any easy way to go the directory that I want? Unlike in windows I can't even copy that directory as text – user4951 Mar 05 '13 at 14:57
  • 17
    In Terminal, you can type cd, then a space, then drag a folder onto the Terminal window and press Return to go to that folder. – Kirk McElhearn Mar 05 '13 at 15:53
  • 4
    In 10.8 and later you can also drag the folder on a Terminal window while holding command. Or if you copy the folder, ⌘V inserts its path in Terminal. – Lri Mar 05 '13 at 16:40
  • 80
    None are convenience for users. For a text file, I have to open up a terminal type a command and drag and drop then type another command! Come on! – malhobayyeb Mar 17 '15 at 05:16
  • You can always use the full path on the command line, and generally don't need to cd (though it can be convenient). touch "$HOME"/Documents/fnord.txt will create fnord.txt in your Documents folder regardless of your current directory. touch /etc/moo will create a file in the system directory /etc (provided you have the privileges to create a file there, which you actually probably don't have). touch path/to/foo will create foo in the directory path/to which is the subdirectory to of the subdirectory path of the current directory. – tripleee Feb 02 '18 at 08:19
  • (The directories need to exist; you can mkdir -p path/to before doing the touch, or figure out how to use the command install to do both in one go.) – tripleee Feb 02 '18 at 08:23
  • 3
    @malhobayyeb My interpretation of this answer is "if you are okay with working on the command line anyway, it's not hard", rather than "you have to use the command line for this". – tripleee Feb 02 '18 at 08:25
  • At least since macos 10.11, you can: select the folder in the Finder, then menu Finder > Services > New Terminal in folder and typing > file.txt will do the job. Since the Terminal is opened in the current folder, you don't need to copy/paste or type its name. In case, this service is not present in your Services menu, you can add it with the Services Preferences. Don't forget to select the folder first. HTH – duthen Nov 02 '18 at 11:53
  • 2
    That's why I use Mac and Ubuntu only for development in some cases and Windows for anything else and also for development – user924 Jun 09 '19 at 14:02
  • A more convenient way to do this nowadays would be to use DTerm, a free app that lets you open a mini command prompt in any Finder window. – calum_b Mar 22 '20 at 18:17
  • 2
    So complicated, tired of reading how to create file in folder. What's wrong with this world? User oriented operating system, damn... – John Smith Apr 16 '20 at 14:14
  • 1
    cannot explain this to my mom – Razvan Tudorica Apr 18 '20 at 12:04
  • @user4951 Copying a file or folder path is actually very easy on a Mac: just select a file or a older and press + + c. Read this answer: How to copy path of a file in Mac OS?. – informatik01 Apr 21 '22 at 05:51
85

The simplest version does not require a file or folder to be selected, and adds a keyboard shortcut of your choice.

Part 1: Create a new Quick Action (was Service)

In Automator, create a new Quick Action (previously called a Service):

enter image description here

From the left side, click Utilities then drag "Run Applescript" over to the right panel.

Change the two pulldown menus at the top of the right panel to read:

Workflow receives no input in Finder.app

Replace ALL the purple script with:

tell application "Finder"
    set txt to make new file at (the target of the front window) as alias with properties {name:"empty.txt"}
    select txt
end tell

Save the Service as "New Empty Text File" (.workflow extension will be added automatically).

This service is now available under the Finder menu in the Finder.

Part 2: Create a Keyboard Shortcut

Under System Preferences › Keyboard › Shortcuts › Services, scroll down to General (it's at the end).

You will see New Empty Text File listed with "none" as the shortcut.

Click on none and type the shortcut of your choice (I used cmd alt N):

enter image description here

You can now type your shortcut in the Finder whenever you want to create a new, empty, text document.

Thanks to Syreeni, whose answer made this possible, and to RoG (comment below) who contributed the line that automatically selects the new file.

Andy Swift
  • 2,210
  • 1
    If "untitled.txt" already exists then the service throws an error message you have to then deal with. Suggest you code in some error handling. – user3439894 Feb 02 '18 at 22:33
  • 6
    You can simply delete " with properties {name:"untitled.txt"}" and it will create sequential empty files. I left it in because I wanted my answer to be as brief as possible and personally, if there's already an empty file, I'd rather be alerted and use it than create a second one. – Andy Swift Feb 05 '18 at 14:03
  • 7
    I added a second applescript line tell application "Finder" to select the file "untitled.txt" so that I can easily find the new file, and hit the return key to rename it. – RoG Sep 29 '18 at 18:02
  • Greate idea, I added it to answer and credited you at the bottom. – Andy Swift Sep 30 '18 at 12:16
  • Great idea, but I would like to use it to create a file on the Desktop. It works everywhere except the Desktop, where it says there is an error (without specifying what error), do you have any idea about why this happens? – GeekInDisguise Mar 20 '19 at 11:36
  • 2
    @Kubuntuer82 This answer to “Right-click, create a new text file. How?” has additional code to check if the desktop is focused and to create the file differently if so. – Rory O'Kane Apr 28 '19 at 20:31
  • Great solution! – Renat Gatin Mar 16 '20 at 03:17
  • 18
    Unbelievable (and unacceptable) that we have to waste time making a custom action in order to do a simple and basic thing that a GUI should have as a default. The solution works, perfectly, and this should be the accepted answer, even if it would be a standard feature of the OS. – Alessandro C May 01 '20 at 14:10
  • I used this applescript in the script editor. Saved it as an app. added this icon to the app in finder http://jugglegood.com/out/finder-control-button.png . Then, added the app to my finder control bar so it's always ready to go. the button is a little smaller than the add folder button, but it doesn't look too bad... finder asks permission the first time, but then it will work quickly. – Scot Nery Sep 07 '20 at 21:08
  • What terminal does easily with one simple command so should gui. Thanks for making this possible! – George Pligoropoulos Oct 09 '21 at 13:38
  • However note the defect that pressing the keyboard shortcut again while the filename is still empty.txt will render an error instead of the nicer solution of creating an extra empty file – George Pligoropoulos Oct 09 '21 at 13:47
  • First, I had trouble finding where the "service" was located. Click on Finder, and at the top of the screen, in the menu bar, click on Finder>Services then scan down to the bottom of the sub menu , and you will see New Empty Text File. Second, you can't just click on a folder and have the text file created in that folder. Instead, you have to double click on the folder, so that Finder actually enters the folder. Third, I liked the solution that lodeOfCode linked to better. I can just click on an icon in the Finder window to add the text file. I'm using macOS 12.3.1. – 7stud May 13 '22 at 19:11
  • How to make it open the text file just created? That would be more efficient. I tried this, but I get a permissions error: tell application "Finder" set txt to make new file at (the target of the front window) as alias with properties {name:"empty.txt"} open txt end tell – Michael Swarts Jun 15 '22 at 20:02
  • 1
    "cmd alt N" shortcut doesn't work for me as it seems to be overridden by an action that opens a new window. As al alternative I used "cmd shift M". – Chiel Jun 25 '22 at 09:42
54

If you have the Finder window open, use Spotlight to open TextEdit. When you're ready to save the file, option+drag the text file icon from the title bar of TextEdit into the Finder window where you want to save it.

nh32rg
  • 704
  • 29
  • The title bar of TextEdit does not have a text file icon. 2. TextEdit does not offer to save it as a simple txt file. Only RTF, .html, odt, word and webarchive is possible
  • – bitbonk Jun 21 '17 at 20:26
  • 4
  • The title bar icon appears shortly after creating the new document. 2. Textedit can be configured to use plain text by default. This means new files will be saved as txt not rtf. 3. I had to option+drag to get it to move the file to the desired location, rather than create a shortcut.
  • – Samuel Coskey Aug 25 '17 at 20:28
  • 4
    This works as long as you set a file name first by clicking the downwards pointing caret at the right hand side of "Untitled". Just set the name, leave "where" as it is, and you are able to drag. – Jasper de Vries Jan 01 '18 at 18:09
  • 7
    As of High Sierra, the easiest way to save as text is to select "Format" > "Make Plain Text" before saving a new file. – tripleee Feb 02 '18 at 08:16
  • You don't have give it any filename. Just Opt+drag the icon on the title bar. Tested on MacOS Montery v12.0.1 – eplictical Jul 19 '22 at 12:33
  • This worked for me but it made a copy in the new location and only save further edits to the original location – Dylan S. Sep 29 '22 at 14:29
  • 1
    Worsssst answer ever, in the entire stackexchage constelation – Marecky Dec 12 '22 at 14:15
  • yeah, I remember I once got here... this sucks alot still in the end of 2022 – Marecky Dec 12 '22 at 14:17
  • Doest not work reliably - icon is missing sometimes. – tim Jul 10 '23 at 16:05
  • On Ventura I need to option-click the TextEdit title bar icon, hold for a fraction of a second, then drag the icon to Finder. If I option click and drag immediately, it doesn't "pick" up the icon, but moves the window instead. Apparently the file is copied though, not moved, so in my case I get a duplicate in iCloud or wherever the default location is. – rerx Oct 31 '23 at 14:38
  • @Marecky Surprisingly, it was accepted by the OP. I thought the point of asking the question was to know the equivalent of Win's right-click txt creation. Which proves that the SE constellation is partly composed of the people who ask questions. – user776686 Dec 22 '23 at 17:06