Mac Finder “Add New File” Context Menu Item – Open Source!

One thing that is not easy from the Mac finder is making a new file. I realize this is a very Unix / Windows way of thinking, to find a place in the filesystem then decide “hey, I need a file here!” instead of making the document and saving it, but it’s the way my mind works when I’m adding one document to a large collection. What I usually do is copy a file in the collection and modify that, but that doesn’t update the file creation date. Grr!

There are apparently a few solutions to this on Mac OS X, but I couldn’t find any that were open source (well, other than doing it in the shell and using touch) so naturally, I wrote my own today. Here it is!

After reading this I realized I could make a Mac Service with Automator. An hour of head-to-desk action later, and we have this:

from this!

The code in text:

$file = "";
while () {
	print $_;
	$file = $_;
}
chomp($file);
$file =~ s/"/\\"/g;
$dir = "";
if (-d $file) {
	$dir = $file;
} else {
	$dir = `dirname "$file"`;
	chomp ($dir);
	$dir =~ s/"/\\"/g;
}
`touch "$dir/newfile.txt"`;
#print "$file -- $dir";

If you want it, you can download it from my site.

Lemme know what you think!

Advertisement

One thought on “Mac Finder “Add New File” Context Menu Item – Open Source!

  1. Hey … thanks for sharing this.
    Any change you can make this work without the need to select a folder … that is, directly by right clicking on the desktop (like in windows)?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s