1

I have a folder open in finder - what is the quickest way to save a new text file to it?

On Windows I would use "New Text" and then edit the file. On the Mac I open a new file in Sublime or Textedit but then I have to select the folder again when I want to save ...?

1

You can run the following AppleScript through a service with keyboard shortcut or context menu item.

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

Alternatively, drag the current directory to Terminal and type touch filename. You can alias the command to something like n for easier activation, and also add closing the Terminal window to the aliased command.

  • I was hoping for a built in command as it's not always my own Mac where I need this. Thanks though! – laktak May 13 '14 at 12:39
  • This is built-in ! And it is the easiest I can think of. – rwenz3l May 13 '14 at 13:13
  • @hcris There is no predefined new file built in method. This however, requires no external software. I have added another method though — see edit. – grg May 13 '14 at 14:18
  • @grgarside After figuring out to drag to the Terminal dock icon instead of the window I really like your touch alternative! Thanks, that work's very well. – laktak May 13 '14 at 14:36
0

Using terminal would be the quickest, all things considered.

Open a terminal and type cd (including a space) and drop the desired target directory into the terminal window, which will basically input the path directory, and hit enter. Then type nano [filename], which will give you a text file to write in. When you're done, type ctrl-x (not cmd) to exit, and confirm filename to save to by hitting y.

Alternatively you can combine step one and two by entering nano path/to/file.txt.

  • 1
    An improvement to this would be to use dterm rather than the built in Terminal.app. Dterm will pop up a command line with the directory set to the folder of the current Finder window, which is handy for all sorts of things : decimus.net/dterm. You could just type 'touch filename.txt' in dterm, and a new empty text file would appear in the Finder window straight away, ready to be opened by whichever app you choose. – calum_b May 13 '14 at 0:33
  • In a similar vein, PathFinder is a vastly superior file browser for Mac, and allows opening a terminal window from the currently browsed directory with a single click, in addition to many more features that improve on Finder. In fact PathFinder has a right-click 'New File…' option as well. Though both Dterm and PathFinder are commercial non-free software. – Jangari May 13 '14 at 1:07
0

The quickest way I've found so far is to

  • drag the current folder from the Path Bar to Favorites
  • in Sublime/Textedit do Save, then select the folder from Favorites
0

You can add this line to Your .bash_profile file:

alias nf="eval \"cd \\\"\\\`osascript -e 'tell app \\\\\\\"Finder\\\\\\\" to return the POSIX path of (target of window 1 as alias)'\\\`\\\"\" && touch filename.txt && open filename.txt"

Then if You type nf in Terminal.app You will create new txt file in the location of the topmost Finder window and open it with Your default application.

You must log in to answer this question.

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