Home » Questions » Computers [ Ask a new question ]

OS X Snow Leopard: Finder automator item for creating a new text file

OS X Snow Leopard: Finder automator item for creating a new text file

how can I create a Finder automaton item that appears in 'Services' for creating a new text file inside a file folder? I use TextMate, so better if the solution is editor-agnostic (rather than using TextEdit).

Asked by: Guest | Views: 256
Total answers/comments: 3
Guest [Entry]

"The way I do it:
I create a dummy text file, and store it in some folder in my documents (this is used as a template for each time the service runs). I then create a workflow (service) as follows:

All you have to do now, is right click the folder you want the new file to be placed in, and select the service created by saving this workflow.

To open the newly created file, you can add an ""open Finder items"" action in which you would obviously select TextMate rather then TextEdit. To make it editor agnostic, you can tell it to open with its default application, and it will do so.

If asking for the name at runtime is very important to you, you can add a get text action, and assign it to a second variable, then add a rename action after the copy action and say replace text, replacing the name of your template file with the text variable. By default, you can't use text variables in the way I described, but the following post provides a work around of doing so. I know it works under 10.6, and may or may not work under earlier version of OSX.

see here for instructions"
Guest [Entry]

"This should work:

do shell script ""echo '[text for the text file]' > [path to folder & file].txt""

If you just want an empty text file, try this:

do shell script "" > [path to folder and file].txt""

Edit: I read your question again... this is an AppleScript. I have more experience with plain Terminal than with Automator and AppleScript, but I assume you can call an AppleScript from Automator?"
Guest [Entry]

"A modification of finiteloop's answer that's a little cleaner.

Create a new service in Automator
Change 'Service receives selected"" to ""folders""
Give it the ""Set Value of Variable"" action, change ""Storage 1"" to a variable called ""dest""
Add the ""New Text File"" action, and drag the variable ""dest"" from the Variable pane at the bottom of the screen onto the ""Where"" field. This is simpler than copying a template file.
Save with a reasonable name.

Now when you click on a folder, you can go to the Services menu at the bottom and find your function.

The function will also appear in the Services settings page; Settings -> Keyboard -> Shortcuts --> Services (left hand side). You can enable and disable it here. You can also assign it a keyboard shortcut. Finally, if you deselect enough items from the Folder submenu (so that there are four or fewer), your function will appear at the bottom of the Context Menu."