CoLT Custom Formats

« Return to the CoLT main page

CoLT allows users to create custom formats when copying both a link’s location and its text together. These custom formats are also available when copying the current page’s location and title. Variables are used to specify the data you want to capture when using a custom format, and their usage depends on whether you are operating on a link or on the current page. Note that these variables all use a percent sign (%) as the first character. If you want an explicit percent embedded in your custom format output, you do so by using %%.

Copying a Link

The following example link will be used to describe the variables available to us when copying a link’s location and text:

A Link to Google

Variable Description Example Value
%T Link text A Link to Google
%U Link location http://www.google.com/
%I Link title attribute text This is the Title Attribute Text
%P Current page title Born Geek » CoLT Custom Formats
%R Current page URL http://www.borngeek.com/firefox/colt/custom-formats/
%S Not used for links
%L Local time (localized time stamp)
%N New line character (new line)
%B Tab character (tab)

Copying the Current Page

When copying the current page location and title, the available variables change meaning. Using this page as our working example, let’s take a look at what each variable means:

Variable Description Example Value
%T Page title Born Geek » CoLT Custom Formats
%U Page location http://www.borngeek.com/firefox/colt/custom-formats/
%I Not used for current page
%P Not used for current page
%R Not used for current page
%S Selected text (any currently selected text)
%L Local time (localized time stamp)
%N New line character (new line)
%B Tab character (tab)

Conditional Statements

Conditional statements, introduced in CoLT 2.6.0, allow you to use a variable if and only if it has a value. This is a very useful way to prevent items with no value from appearing in what is sent to the clipboard. The %?[] variable is how these statements are specified, and a particular syntax is expected. Let’s take a look at several examples of how these can be used in practice.

Simple Conditionals
A simple conditional statement looks like the following: %?[S]. In this example, we’re testing the %S variable which, if you recall, refers to any currently selected text. If the user has selected any text (i.e. the %S variable has a value), its contents will be inserted in the custom format. Otherwise, no text is inserted.
Chaining Simple Conditionals
Simple conditionals can be chained together, as shown in this example: %?[S|T]. Here, we have two variables to test: %S and %T. Variables are always tested from left to right, are always separated by the pipe (|) character, and the first one that has a non-empty value is the one used. In the example I’ve just shown, if the user has selected any text, that selected text will be inserted into the custom format, and the subsequent %T (page title) variable will be ignored. However, if no selected text was present, the %T variable will be tested. If it has a non-empty value (and it almost always will), its value will be used instead. If for some reason it also doesn’t have a value, no text will be inserted.
Conditionals Containing Optional Text
Expanding out from simple conditionals, we can use additional syntax to specify any optional text we want inserted based on the value of a variable. Here’s an example: %?[S{--- %S ---}]. In this example, if the %S variable has a non-empty value, the text between the curly braces, --- %S ---, will be inserted in the custom format (with the embedded %S variable expanded, of course). This usage makes it very easy to include optional text for items like a link’s title text, which may not always be available.
Chaining Optional Text Conditionals
As you might expect, conditionals with optional text can be chained together: %?[S{--- %S ---}|T{=== %T ===}]. Armed with the knowledge from above, you should be able to figure out what the result of this custom format would be given whether or not any text was selected.

Here are a couple examples of actual custom formats showing how conditional statements can be used:

  • <a href="%U">%?[S|T]</a>
    This example demonstrates an HTML-style link whose text will either be set to any selected text, or to the link’s text or page title.
  • %T - %U%?[I{ (%I)}]
    This example will append a link’s title text (wrapped in parentheses) to the default plain text format, if any title-text is present. Otherwise, the plain text format is all that gets copied.