10.6: Create a new file anywhere via an Automator Service

May 12, '10 07:30:00AM

Contributed by: zsaeid

Snow Leopard only hintThis a simple Service for creating new files the currently-open folder in Finder, using AppleScript and Automator.

Start by launching Automator, and in the chooser that appears, select Service. This will open a new Automator window, set up to create a Service. In that window, do the following:

  1. Set the Service to receive selected folders in Finder (the two drop-down menus at the top of the work area on the right). This makes it easier to assign a keyboard shortcut to our service, which we'll do at the end.

  2. Drag and drop the 'Run AppleScript' action (in the Utilities Library) into the work area on the right.

  3. Paste in the following AppleScript, then click the Hammer icon (to compile the code):
    on run {input, parameters}
      tell application "Finder"
        set currentPath to insertion location as text
        set x to POSIX path of currentPath
      end tell
      return x
    end run
  4. Drag and drop the 'Set value of a variable' action from the Utilities Library, and create a new variable called, for example, CurrentFolder. (Do this by clicking on the drop-down menu.)

  5. Drag and drop the New Text File action from the Text library into the work area. Then drag CurrentFolder from the Variable panel at the bottom of the Automator window to the Where entry of the New Text File action. Click the Options button in the action, and click the 'Show this action when the workflow runs' box. This makes it possible to change the name and extension of the new file.

  6. Save the service as 'Create New File,' or whatever you like. Test your new action using the Services menu in Finder, to make sure it works (select a folder, Control-click, and you should see your new Service at the bottom of the contextual menu).

  7. On the Keyboard Shortcuts tab of the Keyboard System Preferences panel, select Services in the left-hand column, and your new service (it should be in the Files and Folders section) in the right-hand panel. Assign a keyboard shortcut to the new Service by double-clicking to the right of the Service's name.

  8. Switch back to Automator and change the leftmost drop-down menu (at the top of the work area) to No Input, then save the Service again.
[crarko adds: This worked as described in testing, except I couldn't get the keyboard shortcut to work when in Column View -- it worked fine in List and Icon view modes. In Column View, though, it would simply try to select the file whose first letter matched the key used in the shortcut.]

Comments (20)

Mac OS X Hints