OSX Finder New File Contextual Menu Item Using Automator

I have always been annoyed that there is no “New File” contextual menu item in OS X’s Finder. I mean, common Apple, why no new file? Anyway, after looking around I found some packages that don’t work with Snow Leopard. So I decided to see what I could do with Automator. Low and behold, there are many options for writing “services” which appear in a the “Services” sub menu of the contextual menu for a folder. I found this simple shell script which creates an empty text document when saved in Automator as a “Service”. (NOTE: there is a better solution below…)

touch "$@/NewTextFile.txt"

I tried messing around with apple script to get a dialog input from the user for the new file’s extension (UPDATE: figured this out, see below), but got incredibly frustrated trying to turn the input folder into a string that could be run as a shell script with the a fore mentioned script. So I gave up and just made a few of the most common blank files I wanted.

Click Here to download a zip of the Automator Workflow files I created. Hopefully this helps someone who is as frustrated as I am with the lack of a “New File” button or contextual menu in OS X.

Please Note: that you must click on the actual folder (with the icon) to get the “Services” menu to appear in Finder’s contextual menu. The “Services” menu does not show when you click on the “background” of the folder in Finder. Annoying.

A Better Solution

UPDATE: Actually got this working the next day when a co-worker mentioned that the folder string i was looking for was called a POSIX (aka Unix) style folder path string. Anyway, I now have a script which is called from the contextual menu, which prompts you for a filename, then creates it in the folder you have clicked on! Yay!

To create this work flow, you can download the service workflow , then put it in the ~/Library/Services/ folder for your user. Alternatively, you can create your own new “Service” with Automator. Open a new workflow as a “Service”, then search for “applescript” in the actions library. Drag the “Run AppleScript” action into your workflow, select “files and folders” in the “service recieves” drop down, then paste this code into the action:

on run {input}
	display dialog "File Name?" default answer "blank.txt"
	set filename to the text returned of result
	set filepath to POSIX path of input
	do shell script "touch " & quoted form of filepath & filename
	return input
end run

Save the service workflow, and blamo, there it is in your contextual menu when clicking on a folder.

3 Comments to OSX Finder New File Contextual Menu Item Using Automator

  1. d's Gravatar d
    March 4, 2011 at 11:42 am | Permalink

    Hello, i tried downloading your files but it didnt work. So i tried creating a new Service pasting your code but I get the following error message: “Can’t get POSIX path of {}. (-1728)”. What does that mean?! Please help! Thank you!

  2. Peter's Gravatar Peter
    May 28, 2013 at 3:52 am | Permalink

    Thanks for the tip!

    You’ll want to use the “quoted form of” for the filename too:

    do shell script “touch ” & quoted form of filepath & quoted form of filename

    This will allow the filename to have spaces and other ‘special’ characters.

Leave a Reply

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>