Creating a Tails Script

A Tails Script is basically a very simple JavaScript file ending with the tails.js extension. To get started, you can build from the sample Tails script here.

Like a Greasemonkey user script, a Tails Script has a metadata section describing how to install the plugin. The metadata section starts with the // ==TailsScript== comment and ends with the // ==/TailsScript== comment. Metadata values are defined the comment format:

// @name value

The supported metadata values are:

  • name - The name of the script. This will be the text of the link if a URL is rendered.
  • namespace - The namespace of the script.
  • description - A description of the script. This will be displayed in the script management window.
  • include - The microformats that this script can operate on. Add multiple include lines for each microformat you support.

When a Tails Script is executed, the contents of the script is loaded within a JavaScript Hash object, so functions and variables must be defined with the name: (variable | function) syntax and separated by commas.

The only method that Tails requires in the script is the getURL function. This function does not have any parameters and should return the URL of the link to render in the Tails view. Not returning anything or returning null will result in the the link not rendering in the view. The method can access the current microformat object by accessing the object instance variable:

getURL: function() { if (this.object.__name == 'hcard'){ /* generate URL... */ } }

In addition to getURL(), you can also specify the following function to further customize the behavior of your script:

  • getLabel() - Returns the label for the generated link. If this method is not defined, the script name will be used instead.

The following instance variables are available to the script in addition to object:

  • sourceURL - The URL of the web page containing the current microformat.
  • label - The name of the script.

Data Object Members

The parsed microformat objects always contain the following member:

  • __name - The name of the microformat (hcard, hcalendar, etc.

The following section lists the members variables/functions that might be available for that particular microformat. Although the specs might specify that some values are required, Tails is pretty forgiving and will more than likely create an object for it anyway. Just to be safe you should make sure that value is available before accessing it.

For the one-worded object members, you can access them with the standard object.name syntax (example: object.fn); However, since multi-word names are usually separated by a dash (-), you’ll need to use the object["name"] syntax instead (example: object["family-name"]).

hAtom

  • Basic member variables - entry-title, entry-content, entry-summary, bookmark
  • JavaScript Date values - updated_date, published_date
  • author_hcard - Post author as an hCard object (see hCard spec below).
  • getTagString() - Returns a comma seperated list of tag names.

hCalendar

  • Basic member variables - dtstart, dtend, summary, location, comment, description, contact, sequence, priority, dtstamp, last-modified, created, recurrence-id, attendee, organizer, url
  • JavaScript Date values - dtstart_date, dtend_date
  • location_hcard - The location as an hCard object (see hCard spec below).

hCard

  • Basic member variables - n, fn, given-name, family-name, title, note, org, locality, region, street-address, postal-code, country-name, email, logo, photo, url
  • tel - An array of telephone numbers (or undefined if none were specified). Each object in the array will at least a value member, and maybe a type member if specified.
  • toAddressString() - Method returning a prettied up version the address (street-address, locality, region, postal-code, country.
  • toStreetAddressLocalityRegionAndPostalCodeString() - Method returning a prettied up string containing street-address, locality, region, postal-code values.
  • toLocalityAndRegionString() - Method returning a prettied up string containing locality, region values.
  • toLocalityRegionAndPostalCodeString() - Method returning a prettied up string containing locality, region, postal-code values.
  • toLocalityRegionAndCountryString() - Method returning a prettied up string containing locality, region, country values.
  • toLocalityRegionPostalCodeAndCountryString() - Method returning a prettied up string containing locality, region, postal-code, country values.

hResume

  • Basic member variable - summary
  • contact_hcard - hCard of the person described in the resume.
  • education - An array or hCalendar events.
  • experience - An array or hCalendar events.
  • skill - An array of skills (String objects).
  • affiliation - An array of hCards.
  • publications - An array of publications (String objects).

hReview

  • Basic member variables - rating, description, summary, type, version, dtreviewed, url
  • JavaScript Date values - dtreviewed_date
  • item - item_hcard variable will be available if an hCard is present and item_hcalendar variable for hCalendar. Otherwise, item.fn, item.photo, or item.url if available. Finally, if none of those values are present, item will be a string of the node’s contents.
  • reviewer - hCard object of the reviewer

xFolk

  • Basic member variable - description
  • taggedlink - Object representing the bookmarked link, containing object members name and url.
  • tags - An array of tags. Each tag object will have object members name and url.

geo

  • Basic member variables - lattitude, longitude, lattitude_label, longitude_label, label.


9 Comments

  • [...] In addition, I also added a page documenting the Tails Script creation, and added a Tails script for del.icio.us and digg. Enjoy. delicious, digg, firefox extension, flock, microformats [...]

  • [...] Für Eifrige gibt es auch noch eine kleine Dokumentation zu Tails und der Script-Erstellung! [...]

  • Clavin,

    Could we use these scripts in stand-alone files for IE to display the data of the Yahoo map?

  • David,

    Do you mean embedding these scripts on an HTML page? If you are, then the answer is no, that won’t work. The scripts are pretty useless without the parser code.

  • [...] En el blog oficial podés ver como crear un tail script y algunos ya listos para usar. [...]

  • David Middleton
    January 3, 2007 at 12:19 pm

    Calvin,

    I’m trying to write a tails script to add hcard contacts to my Plaxo (www.plaxo.com) account.

    I’ve managed to successfully do it, but there are a couple of issues.

    1. Tails does not allow you to add custom parameters into scripts. This would be really useful in lots of cases, but for me it would allow me to remove the hard-coded usename and password needed for communication with Plaxo. It would be nice to have a parameters config section for each tails script, acccessible via the Manage Tails Scripts dialogue.

    2. Using getURL() to perform my Plaxo integration is not ideal, since Plaxo sends a HTTP response with status/error and Tails does not handle this. At the moment, I get a new browser opening with the response it in. Is there some way for Tails to handle this response? Perhaps another method rather than getURL()?

    I would be happy to send a copy of my script if you like. What email is best for you?

    Thanks,

    David.

  • David,

    I’ll probably have to add another method to support, which shouldn’t be a problem. You can email to me at csyu77 at gmail. I’ll have to think about the custom parameters some more.

  • The link to the sample is currently 403′d (Forbidden).

  • KJ, Thank for pointing that out. Its fixed now.

Leave a Reply