Create New File in Finder 2

Posted on April 16, 2012 in Alfred.

Over the weekend I wrote an extension for Alfred to solve the problem of not being able to create new files easily from the Mac OS Finder.

After I had written what was a very rudementary script to solve the problem, I posted it to my blog (the one you're reading now). Within a couple of hours I had over 500 views to the post, and a few comments. Thanks to everyone who took the time to find me on twitter or post a comment.

One of my commenters was Chris Kalafarski (farski). He had re-written my script using Ruby. This had the advantage of running a little faster than mine, and he iterated on it further by adding a filename parameter, and even a system to use predefined templates for the new files. I gave the script a spin, and was delighted. It was a far better solution to my problem.

So I took the liberty of adding a basic help system and packaging the Alfred script as one you can download and install. If you want you can download the raw Ruby script from Chris' Github account here, or just download the .alfredextension below.

Many thanks to Chris for making my life easier. Again, I hope this is as useful to you as it is to me.

downloadfolder Download v2.0 - 10.29 KB

How to use the extension

To create new files with a desired name

Simply load the folder you would like the new file to appear in, in the Finder. Then call up Alfred, and type "new ". You can now enter a new filename to be used for your new file. E.g. "index.html". Your new file will be created in the folder for you instantly.

Providing a new file name to Alfred for the Finder's new file

To add a template

Templates are used for new files of a specific filetype. If for example you want all new HTML files to have a basic HTML structure prefilled, you can add this to your templates directory.

To add a template, you must first create a new template folder inside the extensions folder. To get the extensions folder, right click on the extension name in the Alfred Preferences, and click Show In Finder.

Creating a templates folder in the Alfred Extension

Create the templates folder, and then add your template file inside, using both the name and extension as the filename.

Putting filetype templates into the New File extension for Alfred App

Now when you add a new file to any folder, your template will automatically be used if the filetype matches.

Other things to note

You can create a file, by simply pressing return after typing "new ". This will create an "untitled.txt" file, to be renamed by you later.

Basic help can also be called up using in a growl message, using either 'help' or '?' commands. E.g. "new help".