Easily Create New Files Using Templates

Tip submitted by Jorge G. Mare on Tue, 09/22/2009 - 22:00
Haiku version: 
Development snapshot
Revision number: 
Unknown

In Haiku, creating a new folder is a simple matter: righ-click on the desktop (or your current folder background), select New > New Folder from the popup menu, and your new folder will appear beneath the mouse pointer, ready to be given a name of your choice.

With a little preparation, this very same simple procedure can also be used to create new files of various kinds, such as text, graphic or People files directly from Tracker.

How it works

The way this works is simple. Haiku has a templates folder where you can put template files that Tracker (Haiku's file manager) will use to create your new files. A template is simply a file of any kind that can be either empty of have any number of attributes that may be useful for the purpose (ie., a graphics file of a given size, a Person file from a certain country or company, etc.).

An actual example

Haiku stores contact information in People files. It would be useful to be able to create People files directly from Tracker, so let's see an example of how to do this. The procedure below shows you how to create a People template file and how to place it in the template folder.

  1. Run the People application (Deskbar > Applications > People).
  2. Enter something in the Name field (anything will do), and save the file to the desktop. Since the People file type is called Person, let's call this file Person. You can now close the People application (using the Alt + Q keys or from the File > Quit menu).
  3. Now, let's move the People file template to the templates folder. Right-click on the desktop or on the background of the folder you are in, and select New > Templates folder....This will open Tracker's template folder:
  4. Opening the templates folder from Tracker.

  5. Right-click the desktop and select New > Templates folder.... This will open Tracker's template folder (located in /boot/home/config/settings/Tracker/Tracker New Templates).
  6. Drag-and-drop the People template file that we created on the desktop to the templates folder.

Using the template

You are now ready to use your People template. Right-click on the desktop and select New: you should now see a Person entry in the submenu as shown in the screenshot below.

New people file created from your Tracker template.

Select this entry, and your new People file will be created on the desktop (or whatever folder you may have initiated this action from). The new file is named New Person, but Tracker hands over focus to the filename immediately after it creates the file, so that the user can rename the file to the desired name.

Some ideas

Here are a few ideas of how you can use this method with other file types:

  • Source file templates (html, php, etc.)
  • Wonderbrush files, of various canvas sizes
  • Icon templates, with various standard overlays
  • People files for a certain country, group or company

I am sure there must be other uses. If you can think of any ideas, please share them with us by leaving a comment.