Tapir Syntax

Tapir Icon

What is this "Tapir Syntax"?

As of version 1.1, Tapir can create Menu Applications that change icons, font and formatting on-the-fly. The way to do this is to prepend certain strings to the output from the command or script on which your application is based.

How do I use it?

For argument's sake, let's suppose that your command is the following:

echo "Hello, World"

Suppose that you want this string to be red. You could select the colour when you create the application with Tapir. But you could also do it like this:

echo "TAPIR%%COLOR=red%%Hello, World"

The first part of the string, TAPIR, tells your Tapir application that it is about to receive formatting info. Then follows a list of semi-colon separated values in between the double-percentage (%%) marks.

The Tapir syntax supports setting the following values:

So if you wanted to, say, make a line of output formatted with the font Arial, size 15, colored blue and using the image "foo.png" as icon, you would prepend the output string with the following:

TAPIR%%COLOR=blue;FONT=Arial/15;ICON=foo.png%%

In this case, the path to the image foo.gif is relative, i.e. it is resolved from the Resources folder of your Tapir application, so you must bundle it along with your app.

Having seen how to change icon, size, font and color on the fly with Tapir Syntax, it is perhaps a good idea to create a sample application which utilizes the syntax in a clever way.

Let us imagine that we want to create a Menu Application that displays how much virtual memory is being bound in swap files. Ideally, we can print this piece of information using the du -hs /var/vm command. But if we wish to change the colouring and/or icon based on the output, we need to wrap it in a script.

#!/usr/bin/perl

# Get output from command
$outp = system('du -hs /var/vm');

# See if output makes sense, get unit (i.e. KB, MB, GB) and amount
if ($outp =~ /^(\d+)(M|K|G)*/)
{
    $amount = $1;
    $unit = $2;
}

#################################################
# We use green for anything under 512 megabytes,
# yellow for anything between 512-1024 megabytes,
# red for gigabyte or more of swap memory
##################################################

if ($unit eq 'K' or $amount < 512)
{
    $color = 'green';
}
elsif ($unit eq 'M' and $amount >= 512)
{
    $color = 'yellow';
}
elsif ($unit eq 'G')
{
    $color = 'red';
}

## Here we print the output, using tapir syntax
## to set the output text to the appropriate colour
print "TAPIR%%color=$color%%" . $amount . " " . $unit . "B";