The Open, Edit, View and Help menus are partly controlled by script files that you can customize for your purposes.
In the directory ~/.tint/menus/edit/ are four directories: open, edit, view and help. Interrogator reads the files in these directories upon startup to complete the menus of the same names.
To understand the format of these files so you can customize them,
start by looking at edit/editfiles.sh.
It's got several simple commands listed in it;
each one corresponds to a command on the
Edit > Edit File With menu.
This is one of the commands you might see. (They vary between our Mac and X11 releases.) The whole file is actually two different languages intermingled. It is a shell script file, which is executed when you choose the menu command. It is also a file of directives to Interrogator. These directives are scanned upon program startup. The directives all start with #tint (tint for Tactile Interrogator). The shell uses # for comments and therefore ignores all of those lines. Interrogator scans for #tint and ignores everything else.
1 bbedit)
2 #tintMenuItem bbedit
3 #tintFileCommand "BBEdit"
4 #tintLiveOn
5
6 # bbedit's command-line tool
7 bbedit -u $*
8 ;;
In this example, lines 1, 7 and 8 are all shell script lines. 1 and 8 are part of a case statement; each command is one case. 7 actually runs the command; bbedit is a Macintosh file editor. $* means 'all of the arguments'. -u is a flag passed to BBEdit. If you select two files gtherm.c and gtherm.h and then choose this menu item, the script executes the command
% bbedit -u gtherm.c gtherm.h
Lines 2, 3 and 4 are all Tactile Interrogator directives. #tintMenuItem bbedit introduces a menu item; the keyword bbedit corresponds to the same keyword on line 1 (no connection to line 7). If you select two files gtherm.c and gtherm.h and then choose this menu item, Interrogator executes the command
% editfiles.sh bbedit gtherm.c gtherm.hIn other words, it directly executes the script file, giving it arguments. The first argument tells it to go to the bbedit case. The rest of the arguments become $* for the bbedit command. (The shift shell command, not shown here, shifts it over to get rid of the bbedit keyword so it's just filenames.)
Line 3 introduces a command. #tintFileCommand says that it's a File-oriented command; in other words, you are supposed to choose one or more files as arguments before you choose this command. And the quoted string appears on the menu.
Line 4 is simply a directive that tells Interrogator to
run this program in such a way that it will continue to run
after Interrogator quits.
Without it, your editing session might end if you quit Interrogator.
The #tintFileCommand and the #tintMenuItem directives might seem to do roughly the same thing. But in fact each can be used without the other.
Each script file represents a menu item - either a single-command item, or a submenu of commands. You can see an example of a one-command script file by looking at edit/archive.pl. To make a submenu of commands, follow the pattern in this example:
#tintMenuCommand "Choose your Atom" case "$1" in hydrogen) #tintMenuItem hydrogen ... the Hydrogen command... ;; oxygen) #tintMenuItem oxygen ... the Oxygen command... ;; esac #tintMenuEnd
Notice how the only menu title is for the menu as a whole. This pattern of Tint directives sets up a submenu and declares keywords for each of the submenu's items. Upon execution, the keywords discriminate between subcommands. You don't have to structure your scripts to use case statements this way; in fact edit/perms.sh shows a crafty way to use the keywords directly as arguments to a command.
The omitted sections (with the ...) look exactly like
what a one-command script file.
As such, you can nest inside another submenu by enclosing
another #tintMenuCommand and #tintMenuEnd construct,
with #tintMenuItem items in between.
edit/perms.sh shows this.
Each of these directives starts a command. Each of these has one quoted string on the same line which is required and is the title on the menu.
The script will get two arguments - the name of the directory in its parent in $1, and the full pathname of the directory in $2.
These are directives that appear after a Command directive to modify its meaning or options.
The keystroke code must follow the rules as in the example above. The code is shown as cmdshiftF which stands for the command key modifier (ctrl on X11, clover on Mac) and the Shift modifier, and the key F.
The modifiers are all spelled in lower case (except for the ^) and should all be concatenated at the beginning. The keystroke is after that. If a letter, it's always upper case. Therefore A represents a lower case letter 'a' whereas to make the upper case 'A' you say shiftA.
The keystroke itself should be any upper case letter, digit or punctuation,
or one of these:
Return = enter key
Newline = enter key
Enter = enter key
Tab = tab key
Esc = escape key
Backspace = the backspace or delete key in upper right of alpha pad
Modifiers you can use:
shift = shift key
^ = ctrl key
ctrl = ctrl key
alt = alt key on PC keyboards
opt = option key on Mac keyboards
clover = command (apple-clover) key on Mac keyboards
cmd = clover key on Mac, ctrl key on X11
meta = ctrl key on Mac, alt key on X11
Notice that the last two can be used for platform independence.
For example, Quit is cmdQ on both platforms.
In the example above, the script tries to connect to another computer. Some stuff gets printed out; welcome to whatever computer system. It might look like this if you did it by hand:
sanjuan /usr/X11 > ftp lima Trying lima... Connected to lima. 220 lima FTP server (SunOS 4.8) ready. Login: natasha Password: Last login: Mon May 18 19:35:44 from santiago
As your script runs, Interrogator monitors the output, scanning for Login: and for Password: in the examples above. Each match triggers a dialog to be raised to the Interrogator user. In addition, the total output collects in the Inspector window.
Typically this program seems to ask for the login first and the password second, but it doesn't have to. If they came in the reverse order, the dialogs will come in reverse order. If there was a mistake and it reprompted you, the dialogs will repeat. If for whatever reason, it never asks you for the password or login name, no such dialog will ever be shown.
Example - in this example the script itself prompts for a string (actually a number) so the actual prompt itself is unimportant, so we use MolWt. If you run the script by hand, that's your prompt.
#tintPrompt "MolWt" "Enter the weight of the molecule:" echo "MolWt" read molecularWeight echo "Weight: $molecularWeight" >> assay.txt
Interrogator monitors the stdout and stderr for the process,
and it dictates the stdin input.
When the output contains the exact character string MolWt
(case sensitive),
it will raise a dialog to the user and prompt for a password.
The dialog will have a message that says
Enter the weight of the molecule:
and a box. The user types into the box.
This password will then be fed into the running script's stdin.
The running script does an Echo of the string MolWt (that's a Print statement in borne-shell-ese) and then the read command waits for the user to type in a line and puts the text into the variable $molecularWeight. And then in this example, a final echo statement appends a line with this new data in it to a file.
Note that if there is no such prompt, there will be no dialog. Similarly, if the prompt repeats, the dialog will be re-issued. This is designed to accomodate password prompts such as you would get with the su or ftp commands.
Interrogator doesn't care if it's a prompt line as in the login example, or a complete line with a Newline (Return) at the end. It just scans for the matching text.
These are Unix-process variables that work a little bit like really simple preferences.
Subprocesses tend to inherit the variables from the processes that start them up.
You can substitute their values into your script at runtime by simply including them
prefaced with a dollar sign, as they are listed below.
The exact rules for different shells vary; a good book on shell scripting is recommended if you're not familiar with this.
Or, do a man on these to learn more:
bash tcsh sh csh zsh ksh
To find out which one you are using, try the ps command at the command line.
Interrogator sets these particular variables as described when you run a script.
This is only defined if your script includes the #tintNeedsReopenArgs directive (see also).
It is specifically designed to be fed back into Interrogator, as a command-line argument to trigger the reopening of the same windows as when the script was run by Interrogator. See open/login.sh for an example.
Interrogator is supplied with scripts in Borne shell (.sh) and Perl (.pl). They were chosen because of their ubiquity in the Unix world. Officially, these are the only two scripting languages supported.
You should be able to use any scripting language that follows the
#! rule.
This includes but is not limited to:
- Borne-derived shells sh, ksh, bash, zsh
- C-derived shells csh, tcsh
- perl, python, ruby
Interrogator is actually rather loose about the rules; it scans the first 64k bytes looking for directives. Therefore, you could even use a language that didn't use the #! rule such as Basic, or possibly even a binary program if you were crafty about it. Simply make sure the #tint directives are somewhere in the beginning of the file, probably enclosed in a comment or a text string. In all cases, the program must be able to accept command-line arguments and make sense of them as the scripts do, as described here.
Documentation > Menu Scripts |
|
||||