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?
6 Answers
You can write this in the terminal:
touch filename.txt
Or as a script:
#!/bin/sh
touch filename.txt

- 90,431
- 16
- 141
- 175
-
but then I need a filename first … or using some timestamp, hm … – Bernd Jan 06 '10 at 12:00
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.

- 27,223
- 29
- 105
- 125
-
Ah.. I think you can make Terminal close windows automatically, but you tell it to quit (and probably close just one window, too), with a final line of AppleScript: osascript -e 'Tell application "Terminal" to quit' – xyz Jan 06 '10 at 13:50
How about the unix approach of creating an empty file with touch
?
It could be done in a script, and passed to an application.

- 14,808
- 4
- 33
- 50
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+]

- 109,858
- 19
- 140
- 171
There is another to create new files, you can also create your own templates with it. Just search for NewDoc in AppStore.

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

- 13,890
- 1
- 36
- 60