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

68,365

Solution 1

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.

Solution 2

You can write this in the terminal:

touch filename.txt

Or as a script:

#!/bin/sh
touch filename.txt

Solution 3

How about the unix approach of creating an empty file with touch ?

It could be done in a script, and passed to an application.

Solution 4

Traditional on the shell is to use the touch command. But in any programming language you can do it without running an external program by opening a file with the O_CREAT flag:

in C:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

close(open("myfile.txt", O_WRONLY | O_CREAT | O_TRUNC, 0664)); 

in Perl:

open TEMP '>', 'myfile.txt';
close TEMP;

in Tcl:

close [open "myfile.txt" w+]

Solution 5

There is another to create new files, you can also create your own templates with it. Just search for NewDoc in AppStore.

Share:
68,365
Bernd
Author by

Bernd

Updated on August 05, 2022

Comments

  • Bernd
    Bernd almost 2 years

    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?