Home » Questions » Computers [ Ask a new question ]

Easiest way to create a new text file in a Finder window on OSX

Easiest way to create a new text file in a Finder window on OSX

OK, so if I'm browsing directories in OS X Finder, what's the easiest way to create a new text file?

Asked by: Guest | Views: 33
Total answers/comments: 4
Guest [Entry]

"Nufile does exactly what you want - right click contextual menu for file creation in finder. You can create most any type of file, define template files etc.

The image is for Tiger, in Leopard the 'New file' is a sub-menu of 'More'"
Guest [Entry]

"Another option is to assign a shortcut to a script like this:

tell application ""Finder""
set selection to make new file at (get insertion location)
end tell"
Guest [Entry]

"The AppleScript-based application NewTextFileHere does that, too. Download page is here. It can be dragged to the Finder toolbar, and it can open the file automatically once it's created.

If you open the application package …

… and go to Contents/Resources/Scripts/, you can open main.scpt and edit it. For example, I was annoyed that it only created text files. Change it to the following to just have it create any file you want:

tell application ""Finder"" to set the currentFolder to (folder of the front window as alias)
on error
set the currentFolder to path to desktop folder as alias
end try

set newfilename to """"
(*repeat while newfilename = """"*)
display dialog ""Filename?"" default answer newfilename buttons {""Cancel"", ""OK""} default button 2
set newfilename to text returned of the result
(*end repeat*)
set currentFile to POSIX path of currentFolder & newfilename

do shell script ""touch "" & quoted form of currentFile
do shell script ""open "" & quoted form of currentFile"
Guest [Entry]

"If you use the command line for other purposes as well, you might like DTerm. It provides a pop-up command line whose current directory corresponds to the frontmost window (works with any window which has an icon in the title bar), so you can just press the shortcut and type touch blahblah.txt without needing to change directories.

There are Windows-style contextual menu file creators which are a more direct answer for your problem. But if you are a frequent command line user — if you're the sort who has a project open in an editor and a corresponding terminal window — then DTerm is well worth trying as a broader tool."