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).
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
|show 1 more comment|
This is not an automator action, but resolved the problem of creating a new file where i wanted: http://ignorethecode.net/blog/2009/05/31/creating-new-documents/. Look at the solution called "An Even Better Solution" (bottom of the page).
This should work:
If you just want an empty text file, try this:
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?
Okay, I cheated but you still get an Automator service. You will need to have TextMate setup to use the shell (it usually does this when you first install it, so you can use
Open Automator and create a new Service
From Utilities drag over a Run Shell Script window.
Drop in the following script:
What this basically does is create a file on your desktop named newfile.txt and then open in TextMate.
What this does:
If you select text in an application it will open a blank TextMate file with the name of the selected text, in the frontmost Finder window.
What you are probably trying to do:
Other people have written tutorials on creating a TextMate button that sits in the Finder toolbar that will open blank document in that window, or open a selected file in TextMate. Which is what it sounds like what you want to do and doesn't require Automator.
I'm using this via FastScripts, but it should also work as an Automator service. And yes, this script is ugly even by AppleScript standards.