Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

You can write this in the terminal:

touch filename.txt

Or as a script:

#!/bin/sh
touch filename.txt

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

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

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+]

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

There's a few third party tools that add that kind of functionality. The newest I've seen is Templates

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top