Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating an empty txt file on Mac OS without opening an application first

Tags:

Is there a way to simply create a new document e.g. on the Desktop and open it with e.g. textmate with a simple shortcut or script. I know that the MS Windows approach where you can just create a new empty txt file directly is not working for Mac. I am looking for a method achieving something similar. Any ideas?

like image 258
Bernd Avatar asked Jan 06 '10 11:01

Bernd


People also ask

How do I create a blank text file?

Another way to create a text file is to right-click an empty area on the desktop, and in the pop-up menu, select New, and then select Text Document. Creating a text file this way opens your default text editor with a blank text file on your desktop.

What is the quickest way to create an empty file?

From within Windows, right-click in the area you want to create the file. For example, right-click the desktop to create a new text file on the desktop. In the drop-down menu that appears, select New and choose Text Document.

How do you create a new file on Mac?

On your Mac, click the Finder icon in the Dock to open a Finder window, then navigate to where you want to create the folder. Alternatively, click the desktop if you want to create the folder on the desktop. Choose File > New Folder, or press Shift-Command-N.


2 Answers

You can write this in the terminal:

touch filename.txt 

Or as a script:

#!/bin/sh touch filename.txt 
like image 54
Emil Vikström Avatar answered Sep 30 '22 05:09

Emil Vikström


alt text http://img64.imageshack.us/img64/2280/screenshot20100106at125.png

This uses TextMate's mate command line helper application.

If it's not installed, go to TextMate > Help > Terminal Usage.


#!/bin/bash cd "$(dirname "$0")" ntf="Untitled $(date +%s).txt" touch "$ntf" mate "$ntf" 
  • Save this on your Desktop as "New Text File.command"
  • Make it executable (in Terminal: chmod +x "New Text File.command")
  • Optional: Copy and paste the TextMate icon from TextMate.app's "Get Info" dialog in to your new file's "Get Info" dialog.
like image 32
xyz Avatar answered Sep 30 '22 05:09

xyz